]>
Commit | Line | Data |
---|---|---|
abe529af | 1 | /* |
39cc5c4a | 2 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc. |
abe529af BP |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #include <config.h> | |
abe529af BP |
18 | #include <errno.h> |
19 | ||
ccc09689 | 20 | #include "bfd.h" |
abe529af | 21 | #include "bond.h" |
daff3353 | 22 | #include "bundle.h" |
abe529af | 23 | #include "byte-order.h" |
f23d157c | 24 | #include "connectivity.h" |
abe529af BP |
25 | #include "connmgr.h" |
26 | #include "coverage.h" | |
27 | #include "cfm.h" | |
28 | #include "dpif.h" | |
abe529af | 29 | #include "fail-open.h" |
05067881 | 30 | #include "guarded-list.h" |
abe529af BP |
31 | #include "hmapx.h" |
32 | #include "lacp.h" | |
75a75043 | 33 | #include "learn.h" |
abe529af | 34 | #include "mac-learning.h" |
6d95c4e8 | 35 | #include "mcast-snooping.h" |
abe529af | 36 | #include "multipath.h" |
0a740f48 | 37 | #include "netdev-vport.h" |
abe529af BP |
38 | #include "netdev.h" |
39 | #include "netlink.h" | |
40 | #include "nx-match.h" | |
41 | #include "odp-util.h" | |
1ac7c9bd | 42 | #include "odp-execute.h" |
b598f214 BW |
43 | #include "ofproto/ofproto-dpif.h" |
44 | #include "ofproto/ofproto-provider.h" | |
29089a54 | 45 | #include "ofproto-dpif-ipfix.h" |
ec7ceaed | 46 | #include "ofproto-dpif-mirror.h" |
635c5db9 | 47 | #include "ofproto-dpif-monitor.h" |
f5374617 | 48 | #include "ofproto-dpif-rid.h" |
bae473fe | 49 | #include "ofproto-dpif-sflow.h" |
e1ec7dd4 | 50 | #include "ofproto-dpif-upcall.h" |
9583bc14 | 51 | #include "ofproto-dpif-xlate.h" |
b598f214 BW |
52 | #include "openvswitch/ofp-actions.h" |
53 | #include "openvswitch/dynamic-string.h" | |
54 | #include "openvswitch/meta-flow.h" | |
55 | #include "openvswitch/ofp-parse.h" | |
25d436fb | 56 | #include "openvswitch/ofp-print.h" |
b598f214 BW |
57 | #include "openvswitch/ofp-util.h" |
58 | #include "openvswitch/ofpbuf.h" | |
59 | #include "openvswitch/vlog.h" | |
60 | #include "ovs-lldp.h" | |
dfba2dfc | 61 | #include "ovs-rcu.h" |
a36de779 | 62 | #include "ovs-router.h" |
b598f214 | 63 | #include "poll-loop.h" |
f23d157c | 64 | #include "seq.h" |
0d085684 | 65 | #include "simap.h" |
27022416 | 66 | #include "smap.h" |
abe529af | 67 | #include "timer.h" |
b9ad7294 | 68 | #include "tunnel.h" |
6c1491fb | 69 | #include "unaligned.h" |
abe529af | 70 | #include "unixctl.h" |
ee89ea7b | 71 | #include "util.h" |
abe529af | 72 | #include "vlan-bitmap.h" |
abe529af BP |
73 | |
74 | VLOG_DEFINE_THIS_MODULE(ofproto_dpif); | |
75 | ||
abe529af | 76 | COVERAGE_DEFINE(ofproto_dpif_expired); |
ada3a58d | 77 | COVERAGE_DEFINE(packet_in_overflow); |
abe529af | 78 | |
a088a1ff | 79 | struct flow_miss; |
abe529af | 80 | |
70742c7f EJ |
81 | struct rule_dpif { |
82 | struct rule up; | |
83 | ||
84 | /* These statistics: | |
85 | * | |
e79a6c83 EJ |
86 | * - Do include packets and bytes from datapath flows which have not |
87 | * recently been processed by a revalidator. */ | |
70742c7f | 88 | struct ovs_mutex stats_mutex; |
1a4ec18d | 89 | struct dpif_flow_stats stats OVS_GUARDED; |
888ac0d7 | 90 | |
39c94593 JR |
91 | /* In non-NULL, will point to a new rule (for which a reference is held) to |
92 | * which all the stats updates should be forwarded. This exists only | |
93 | * transitionally when flows are replaced. | |
94 | * | |
95 | * Protected by stats_mutex. If both 'rule->stats_mutex' and | |
96 | * 'rule->new_rule->stats_mutex' must be held together, acquire them in that | |
97 | * order, */ | |
98 | struct rule_dpif *new_rule OVS_GUARDED; | |
99 | ||
888ac0d7 SH |
100 | /* If non-zero then the recirculation id that has |
101 | * been allocated for use with this rule. | |
102 | * The recirculation id and associated internal flow should | |
103 | * be freed when the rule is freed */ | |
104 | uint32_t recirc_id; | |
70742c7f EJ |
105 | }; |
106 | ||
003ce655 JR |
107 | /* RULE_CAST() depends on this. */ |
108 | BUILD_ASSERT_DECL(offsetof(struct rule_dpif, up) == 0); | |
109 | ||
dc437090 JR |
110 | static void rule_get_stats(struct rule *, uint64_t *packets, uint64_t *bytes, |
111 | long long int *used); | |
70742c7f | 112 | static struct rule_dpif *rule_dpif_cast(const struct rule *); |
f5857865 | 113 | static void rule_expire(struct rule_dpif *, long long now); |
b0f7b9b5 | 114 | |
00430a3f SH |
115 | struct group_dpif { |
116 | struct ofgroup up; | |
117 | ||
118 | /* These statistics: | |
119 | * | |
e79a6c83 EJ |
120 | * - Do include packets and bytes from datapath flows which have not |
121 | * recently been processed by a revalidator. */ | |
00430a3f SH |
122 | struct ovs_mutex stats_mutex; |
123 | uint64_t packet_count OVS_GUARDED; /* Number of packets received. */ | |
124 | uint64_t byte_count OVS_GUARDED; /* Number of bytes received. */ | |
00430a3f SH |
125 | }; |
126 | ||
46c88433 EJ |
127 | struct ofbundle { |
128 | struct hmap_node hmap_node; /* In struct ofproto's "bundles" hmap. */ | |
129 | struct ofproto_dpif *ofproto; /* Owning ofproto. */ | |
130 | void *aux; /* Key supplied by ofproto's client. */ | |
131 | char *name; /* Identifier for log messages. */ | |
132 | ||
133 | /* Configuration. */ | |
ca6ba700 | 134 | struct ovs_list ports; /* Contains "struct ofport"s. */ |
46c88433 EJ |
135 | enum port_vlan_mode vlan_mode; /* VLAN mode */ |
136 | int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */ | |
137 | unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1. | |
138 | * NULL if all VLANs are trunked. */ | |
139 | struct lacp *lacp; /* LACP if LACP is enabled, otherwise NULL. */ | |
140 | struct bond *bond; /* Nonnull iff more than one port. */ | |
141 | bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */ | |
142 | ||
143 | /* Status. */ | |
144 | bool floodable; /* True if no port has OFPUTIL_PC_NO_FLOOD set. */ | |
145 | }; | |
146 | ||
abe529af | 147 | static void bundle_remove(struct ofport *); |
7bde8dd8 | 148 | static void bundle_update(struct ofbundle *); |
abe529af BP |
149 | static void bundle_destroy(struct ofbundle *); |
150 | static void bundle_del_port(struct ofport_dpif *); | |
151 | static void bundle_run(struct ofbundle *); | |
152 | static void bundle_wait(struct ofbundle *); | |
66ff280d | 153 | static void bundle_flush_macs(struct ofbundle *, bool); |
2372c146 | 154 | static void bundle_move(struct ofbundle *, struct ofbundle *); |
33158a18 | 155 | |
21f7563c JP |
156 | static void stp_run(struct ofproto_dpif *ofproto); |
157 | static void stp_wait(struct ofproto_dpif *ofproto); | |
851bf71d EJ |
158 | static int set_stp_port(struct ofport *, |
159 | const struct ofproto_port_stp_settings *); | |
21f7563c | 160 | |
9efd308e DV |
161 | static void rstp_run(struct ofproto_dpif *ofproto); |
162 | static void set_rstp_port(struct ofport *, | |
163 | const struct ofproto_port_rstp_settings *); | |
164 | ||
46c88433 EJ |
165 | struct ofport_dpif { |
166 | struct hmap_node odp_port_node; /* In dpif_backer's "odp_to_ofport_map". */ | |
167 | struct ofport up; | |
168 | ||
169 | odp_port_t odp_port; | |
170 | struct ofbundle *bundle; /* Bundle that contains this port, if any. */ | |
ca6ba700 | 171 | struct ovs_list bundle_node;/* In struct ofbundle's "ports" list. */ |
46c88433 EJ |
172 | struct cfm *cfm; /* Connectivity Fault Management, if any. */ |
173 | struct bfd *bfd; /* BFD, if any. */ | |
0477baa9 | 174 | struct lldp *lldp; /* lldp, if any. */ |
46c88433 EJ |
175 | bool may_enable; /* May be enabled in bonds. */ |
176 | bool is_tunnel; /* This port is a tunnel. */ | |
a6363cfd | 177 | bool is_layer3; /* This is a layer 3 port. */ |
46c88433 EJ |
178 | long long int carrier_seq; /* Carrier status changes. */ |
179 | struct ofport_dpif *peer; /* Peer if patch port. */ | |
180 | ||
181 | /* Spanning tree. */ | |
182 | struct stp_port *stp_port; /* Spanning Tree Protocol, if any. */ | |
183 | enum stp_state stp_state; /* Always STP_DISABLED if STP not in use. */ | |
184 | long long int stp_state_entered; | |
185 | ||
9efd308e DV |
186 | /* Rapid Spanning Tree. */ |
187 | struct rstp_port *rstp_port; /* Rapid Spanning Tree Protocol, if any. */ | |
188 | enum rstp_state rstp_state; /* Always RSTP_DISABLED if RSTP not in use. */ | |
189 | ||
55954f6e EJ |
190 | /* Queue to DSCP mapping. */ |
191 | struct ofproto_port_queue *qdscp; | |
192 | size_t n_qdscp; | |
46c88433 EJ |
193 | }; |
194 | ||
46c88433 EJ |
195 | static odp_port_t ofp_port_to_odp_port(const struct ofproto_dpif *, |
196 | ofp_port_t); | |
197 | ||
4e022ec0 | 198 | static ofp_port_t odp_port_to_ofp_port(const struct ofproto_dpif *, |
46c88433 | 199 | odp_port_t); |
e1b1d06a | 200 | |
abe529af BP |
201 | static struct ofport_dpif * |
202 | ofport_dpif_cast(const struct ofport *ofport) | |
203 | { | |
abe529af BP |
204 | return ofport ? CONTAINER_OF(ofport, struct ofport_dpif, up) : NULL; |
205 | } | |
206 | ||
207 | static void port_run(struct ofport_dpif *); | |
8aee94b6 | 208 | static int set_bfd(struct ofport *, const struct smap *); |
a5610457 | 209 | static int set_cfm(struct ofport *, const struct cfm_settings *); |
0477baa9 | 210 | static int set_lldp(struct ofport *ofport_, const struct smap *cfg); |
6cbbf4fa | 211 | static void ofport_update_peer(struct ofport_dpif *); |
abe529af | 212 | |
e79a6c83 EJ |
213 | /* Reasons that we might need to revalidate every datapath flow, and |
214 | * corresponding coverage counters. | |
cdc3ab65 EJ |
215 | * |
216 | * A value of 0 means that there is no need to revalidate. | |
217 | * | |
218 | * It would be nice to have some cleaner way to integrate with coverage | |
219 | * counters, but with only a few reasons I guess this is good enough for | |
220 | * now. */ | |
221 | enum revalidate_reason { | |
222 | REV_RECONFIGURE = 1, /* Switch configuration changed. */ | |
223 | REV_STP, /* Spanning tree protocol port status change. */ | |
9efd308e | 224 | REV_RSTP, /* RSTP port status change. */ |
4a1b8f30 | 225 | REV_BOND, /* Bonding changed. */ |
cdc3ab65 EJ |
226 | REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/ |
227 | REV_FLOW_TABLE, /* Flow table changed. */ | |
30618594 | 228 | REV_MAC_LEARNING, /* Mac learning changed. */ |
6d95c4e8 | 229 | REV_MCAST_SNOOPING, /* Multicast snooping changed. */ |
cdc3ab65 | 230 | }; |
3c4a309c BP |
231 | COVERAGE_DEFINE(rev_reconfigure); |
232 | COVERAGE_DEFINE(rev_stp); | |
9efd308e | 233 | COVERAGE_DEFINE(rev_rstp); |
4a1b8f30 | 234 | COVERAGE_DEFINE(rev_bond); |
3c4a309c BP |
235 | COVERAGE_DEFINE(rev_port_toggled); |
236 | COVERAGE_DEFINE(rev_flow_table); | |
30618594 | 237 | COVERAGE_DEFINE(rev_mac_learning); |
6d95c4e8 | 238 | COVERAGE_DEFINE(rev_mcast_snooping); |
3c4a309c | 239 | |
cdc3ab65 EJ |
240 | /* All datapaths of a given type share a single dpif backer instance. */ |
241 | struct dpif_backer { | |
242 | char *type; | |
243 | int refcount; | |
244 | struct dpif *dpif; | |
e1ec7dd4 | 245 | struct udpif *udpif; |
8449c4d6 EJ |
246 | |
247 | struct ovs_rwlock odp_to_ofport_lock; | |
390eadaa | 248 | struct hmap odp_to_ofport_map OVS_GUARDED; /* Contains "struct ofport"s. */ |
cdc3ab65 EJ |
249 | |
250 | struct simap tnl_backers; /* Set of dpif ports backing tunnels. */ | |
251 | ||
e79a6c83 | 252 | enum revalidate_reason need_revalidate; /* Revalidate all flows. */ |
cdc3ab65 | 253 | |
cdc3ab65 | 254 | bool recv_set_enable; /* Enables or disables receiving packets. */ |
4b97b70d | 255 | |
b5cbbcf6 AZ |
256 | /* Version string of the datapath stored in OVSDB. */ |
257 | char *dp_version_string; | |
a36de779 | 258 | |
b440dd8c JS |
259 | /* Datapath feature support. */ |
260 | struct dpif_backer_support support; | |
a36de779 | 261 | struct atomic_count tnl_count; |
cdc3ab65 EJ |
262 | }; |
263 | ||
acf60855 JP |
264 | /* All existing ofproto_backer instances, indexed by ofproto->up.type. */ |
265 | static struct shash all_dpif_backers = SHASH_INITIALIZER(&all_dpif_backers); | |
266 | ||
46c88433 EJ |
267 | struct ofproto_dpif { |
268 | struct hmap_node all_ofproto_dpifs_node; /* In 'all_ofproto_dpifs'. */ | |
269 | struct ofproto up; | |
270 | struct dpif_backer *backer; | |
271 | ||
290835f9 BP |
272 | /* Unique identifier for this instantiation of this bridge in this running |
273 | * process. */ | |
274 | struct uuid uuid; | |
275 | ||
44e0c35d | 276 | ATOMIC(ovs_version_t) tables_version; /* For classifier lookups. */ |
621b8064 | 277 | |
e79a6c83 EJ |
278 | uint64_t dump_seq; /* Last read of udpif_dump_seq(). */ |
279 | ||
46c88433 EJ |
280 | /* Special OpenFlow rules. */ |
281 | struct rule_dpif *miss_rule; /* Sends flow table misses to controller. */ | |
282 | struct rule_dpif *no_packet_in_rule; /* Drops flow table misses. */ | |
ad99e2ed | 283 | struct rule_dpif *drop_frags_rule; /* Used in OFPUTIL_FRAG_DROP mode. */ |
46c88433 EJ |
284 | |
285 | /* Bridging. */ | |
286 | struct netflow *netflow; | |
287 | struct dpif_sflow *sflow; | |
288 | struct dpif_ipfix *ipfix; | |
289 | struct hmap bundles; /* Contains "struct ofbundle"s. */ | |
290 | struct mac_learning *ml; | |
6d95c4e8 | 291 | struct mcast_snooping *ms; |
46c88433 | 292 | bool has_bonded_bundles; |
e2d13c43 | 293 | bool lacp_enabled; |
46c88433 EJ |
294 | struct mbridge *mbridge; |
295 | ||
0da3c61b AW |
296 | struct ovs_mutex stats_mutex; |
297 | struct netdev_stats stats OVS_GUARDED; /* To account packets generated and | |
298 | * consumed in userspace. */ | |
46c88433 EJ |
299 | |
300 | /* Spanning tree. */ | |
301 | struct stp *stp; | |
302 | long long int stp_last_tick; | |
303 | ||
9efd308e DV |
304 | /* Rapid Spanning Tree. */ |
305 | struct rstp *rstp; | |
306 | long long int rstp_last_tick; | |
307 | ||
46c88433 EJ |
308 | /* Ports. */ |
309 | struct sset ports; /* Set of standard port names. */ | |
310 | struct sset ghost_ports; /* Ports with no datapath port. */ | |
311 | struct sset port_poll_set; /* Queued names for port_poll() reply. */ | |
312 | int port_poll_errno; /* Last errno for port_poll() reply. */ | |
f23d157c | 313 | uint64_t change_seq; /* Connectivity status changes. */ |
46c88433 | 314 | |
3d9c5e58 | 315 | /* Work queues. */ |
a2b53dec BP |
316 | struct guarded_list ams; /* Contains "struct ofproto_async_msgs"s. */ |
317 | struct seq *ams_seq; /* For notifying 'ams' reception. */ | |
318 | uint64_t ams_seqno; | |
46c88433 EJ |
319 | }; |
320 | ||
b44a10b7 BP |
321 | /* All existing ofproto_dpif instances, indexed by ->up.name. */ |
322 | static struct hmap all_ofproto_dpifs = HMAP_INITIALIZER(&all_ofproto_dpifs); | |
323 | ||
a36de779 PS |
324 | static bool ofproto_use_tnl_push_pop = true; |
325 | static void ofproto_unixctl_init(void); | |
abe529af | 326 | |
46c88433 EJ |
327 | static inline struct ofproto_dpif * |
328 | ofproto_dpif_cast(const struct ofproto *ofproto) | |
329 | { | |
330 | ovs_assert(ofproto->ofproto_class == &ofproto_dpif_class); | |
331 | return CONTAINER_OF(ofproto, struct ofproto_dpif, up); | |
332 | } | |
333 | ||
adcf00ba | 334 | bool |
2494ccd7 | 335 | ofproto_dpif_get_enable_ufid(const struct dpif_backer *backer) |
adcf00ba | 336 | { |
2494ccd7 | 337 | return backer->support.ufid; |
adcf00ba AZ |
338 | } |
339 | ||
2494ccd7 JS |
340 | struct dpif_backer_support * |
341 | ofproto_dpif_get_support(const struct ofproto_dpif *ofproto) | |
8e1ffd75 | 342 | { |
2494ccd7 | 343 | return &ofproto->backer->support; |
8e1ffd75 JS |
344 | } |
345 | ||
adcf00ba | 346 | static void ofproto_trace(struct ofproto_dpif *, struct flow *, |
cf62fa4c | 347 | const struct dp_packet *packet, |
aee0979b BP |
348 | const struct ofpact[], size_t ofpacts_len, |
349 | struct ds *); | |
46c88433 | 350 | |
abe529af BP |
351 | /* Global variables. */ |
352 | static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); | |
acf60855 JP |
353 | |
354 | /* Initial mappings of port to bridge mappings. */ | |
355 | static struct shash init_ofp_ports = SHASH_INITIALIZER(&init_ofp_ports); | |
46c88433 | 356 | |
1b63b91e BP |
357 | /* Executes 'fm'. The caller retains ownership of 'fm' and everything in |
358 | * it. */ | |
3d9c5e58 | 359 | void |
46c88433 | 360 | ofproto_dpif_flow_mod(struct ofproto_dpif *ofproto, |
8be00367 | 361 | const struct ofputil_flow_mod *fm) |
46c88433 | 362 | { |
8be00367 JR |
363 | struct ofproto_flow_mod ofm; |
364 | ||
365 | /* Multiple threads may do this for the same 'fm' at the same time. | |
366 | * Allocate ofproto_flow_mod with execution context from stack. | |
367 | * | |
368 | * Note: This copy could be avoided by making ofproto_flow_mod more | |
369 | * complex, but that may not be desireable, and a learn action is not that | |
370 | * fast to begin with. */ | |
371 | ofm.fm = *fm; | |
372 | ofproto_flow_mod(&ofproto->up, &ofm); | |
46c88433 EJ |
373 | } |
374 | ||
a2b53dec BP |
375 | /* Appends 'am' to the queue of asynchronous messages to be sent to the |
376 | * controller. Takes ownership of 'am' and any data it points to. */ | |
46c88433 | 377 | void |
a2b53dec BP |
378 | ofproto_dpif_send_async_msg(struct ofproto_dpif *ofproto, |
379 | struct ofproto_async_msg *am) | |
46c88433 | 380 | { |
a2b53dec | 381 | if (!guarded_list_push_back(&ofproto->ams, &am->list_node, 1024)) { |
ada3a58d | 382 | COVERAGE_INC(packet_in_overflow); |
a2b53dec | 383 | ofproto_async_msg_free(am); |
ada3a58d | 384 | } |
cfc50ae5 AW |
385 | |
386 | /* Wakes up main thread for packet-in I/O. */ | |
a2b53dec | 387 | seq_change(ofproto->ams_seq); |
46c88433 | 388 | } |
6b83a3c5 SH |
389 | |
390 | /* The default "table-miss" behaviour for OpenFlow1.3+ is to drop the | |
391 | * packet rather than to send the packet to the controller. | |
392 | * | |
393 | * This function returns false to indicate that a packet_in message | |
394 | * for a "table-miss" should be sent to at least one controller. | |
395 | * False otherwise. */ | |
396 | bool | |
397 | ofproto_dpif_wants_packet_in_on_miss(struct ofproto_dpif *ofproto) | |
398 | { | |
399 | return connmgr_wants_packet_in_on_miss(ofproto->up.connmgr); | |
400 | } | |
abe529af BP |
401 | \f |
402 | /* Factory functions. */ | |
403 | ||
b0408fca | 404 | static void |
acf60855 | 405 | init(const struct shash *iface_hints) |
b0408fca | 406 | { |
acf60855 JP |
407 | struct shash_node *node; |
408 | ||
409 | /* Make a local copy, since we don't own 'iface_hints' elements. */ | |
410 | SHASH_FOR_EACH(node, iface_hints) { | |
411 | const struct iface_hint *orig_hint = node->data; | |
412 | struct iface_hint *new_hint = xmalloc(sizeof *new_hint); | |
413 | ||
414 | new_hint->br_name = xstrdup(orig_hint->br_name); | |
415 | new_hint->br_type = xstrdup(orig_hint->br_type); | |
416 | new_hint->ofp_port = orig_hint->ofp_port; | |
417 | ||
418 | shash_add(&init_ofp_ports, node->name, new_hint); | |
419 | } | |
0fc1f5c0 HH |
420 | |
421 | ofproto_unixctl_init(); | |
422 | udpif_init(); | |
b0408fca JP |
423 | } |
424 | ||
abe529af BP |
425 | static void |
426 | enumerate_types(struct sset *types) | |
427 | { | |
428 | dp_enumerate_types(types); | |
429 | } | |
430 | ||
431 | static int | |
432 | enumerate_names(const char *type, struct sset *names) | |
433 | { | |
acf60855 JP |
434 | struct ofproto_dpif *ofproto; |
435 | ||
436 | sset_clear(names); | |
437 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
438 | if (strcmp(type, ofproto->up.type)) { | |
439 | continue; | |
440 | } | |
441 | sset_add(names, ofproto->up.name); | |
442 | } | |
443 | ||
444 | return 0; | |
abe529af BP |
445 | } |
446 | ||
447 | static int | |
448 | del(const char *type, const char *name) | |
449 | { | |
450 | struct dpif *dpif; | |
451 | int error; | |
452 | ||
453 | error = dpif_open(name, type, &dpif); | |
454 | if (!error) { | |
455 | error = dpif_delete(dpif); | |
456 | dpif_close(dpif); | |
457 | } | |
458 | return error; | |
459 | } | |
460 | \f | |
0aeaabc8 JP |
461 | static const char * |
462 | port_open_type(const char *datapath_type, const char *port_type) | |
463 | { | |
464 | return dpif_port_open_type(datapath_type, port_type); | |
465 | } | |
466 | ||
acf60855 JP |
467 | /* Type functions. */ |
468 | ||
36beb9be BP |
469 | static void process_dpif_port_changes(struct dpif_backer *); |
470 | static void process_dpif_all_ports_changed(struct dpif_backer *); | |
471 | static void process_dpif_port_change(struct dpif_backer *, | |
472 | const char *devname); | |
473 | static void process_dpif_port_error(struct dpif_backer *, int error); | |
474 | ||
476cb42a BP |
475 | static struct ofproto_dpif * |
476 | lookup_ofproto_dpif_by_port_name(const char *name) | |
477 | { | |
478 | struct ofproto_dpif *ofproto; | |
479 | ||
480 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
481 | if (sset_contains(&ofproto->ports, name)) { | |
482 | return ofproto; | |
483 | } | |
484 | } | |
485 | ||
486 | return NULL; | |
487 | } | |
488 | ||
d997f23f ZK |
489 | bool |
490 | ofproto_dpif_backer_enabled(struct dpif_backer* backer) | |
491 | { | |
492 | return backer->recv_set_enable; | |
493 | } | |
494 | ||
acf60855 JP |
495 | static int |
496 | type_run(const char *type) | |
497 | { | |
498 | struct dpif_backer *backer; | |
acf60855 JP |
499 | |
500 | backer = shash_find_data(&all_dpif_backers, type); | |
501 | if (!backer) { | |
502 | /* This is not necessarily a problem, since backers are only | |
503 | * created on demand. */ | |
504 | return 0; | |
505 | } | |
506 | ||
c9aa1086 DDP |
507 | /* This must be called before dpif_run() */ |
508 | dpif_poll_threads_set(backer->dpif, pmd_cpu_mask); | |
a36de779 PS |
509 | |
510 | if (dpif_run(backer->dpif)) { | |
511 | backer->need_revalidate = REV_RECONFIGURE; | |
512 | } | |
513 | ||
27f57736 | 514 | udpif_run(backer->udpif); |
acf60855 | 515 | |
40358701 GS |
516 | /* If vswitchd started with other_config:flow_restore_wait set as "true", |
517 | * and the configuration has now changed to "false", enable receiving | |
518 | * packets from the datapath. */ | |
519 | if (!backer->recv_set_enable && !ofproto_get_flow_restore_wait()) { | |
36beb9be BP |
520 | int error; |
521 | ||
40358701 GS |
522 | backer->recv_set_enable = true; |
523 | ||
524 | error = dpif_recv_set(backer->dpif, backer->recv_set_enable); | |
525 | if (error) { | |
526 | VLOG_ERR("Failed to enable receiving packets in dpif."); | |
527 | return error; | |
528 | } | |
529 | dpif_flow_flush(backer->dpif); | |
530 | backer->need_revalidate = REV_RECONFIGURE; | |
531 | } | |
532 | ||
6567010f | 533 | if (backer->recv_set_enable) { |
e79a6c83 | 534 | udpif_set_threads(backer->udpif, n_handlers, n_revalidators); |
448a4b2f AW |
535 | } |
536 | ||
a1616063 | 537 | if (backer->need_revalidate) { |
2cc3c58e | 538 | struct ofproto_dpif *ofproto; |
a614d823 KM |
539 | struct simap_node *node; |
540 | struct simap tmp_backers; | |
541 | ||
542 | /* Handle tunnel garbage collection. */ | |
543 | simap_init(&tmp_backers); | |
544 | simap_swap(&backer->tnl_backers, &tmp_backers); | |
545 | ||
546 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
547 | struct ofport_dpif *iter; | |
548 | ||
549 | if (backer != ofproto->backer) { | |
550 | continue; | |
551 | } | |
552 | ||
553 | HMAP_FOR_EACH (iter, up.hmap_node, &ofproto->up.ports) { | |
3aa30359 | 554 | char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; |
a614d823 KM |
555 | const char *dp_port; |
556 | ||
42943cde | 557 | if (!iter->is_tunnel) { |
a614d823 KM |
558 | continue; |
559 | } | |
560 | ||
3aa30359 BP |
561 | dp_port = netdev_vport_get_dpif_port(iter->up.netdev, |
562 | namebuf, sizeof namebuf); | |
a614d823 KM |
563 | node = simap_find(&tmp_backers, dp_port); |
564 | if (node) { | |
565 | simap_put(&backer->tnl_backers, dp_port, node->data); | |
566 | simap_delete(&tmp_backers, node); | |
567 | node = simap_find(&backer->tnl_backers, dp_port); | |
568 | } else { | |
569 | node = simap_find(&backer->tnl_backers, dp_port); | |
570 | if (!node) { | |
4e022ec0 | 571 | odp_port_t odp_port = ODPP_NONE; |
a614d823 KM |
572 | |
573 | if (!dpif_port_add(backer->dpif, iter->up.netdev, | |
574 | &odp_port)) { | |
4e022ec0 AW |
575 | simap_put(&backer->tnl_backers, dp_port, |
576 | odp_to_u32(odp_port)); | |
a614d823 KM |
577 | node = simap_find(&backer->tnl_backers, dp_port); |
578 | } | |
579 | } | |
580 | } | |
581 | ||
4e022ec0 | 582 | iter->odp_port = node ? u32_to_odp(node->data) : ODPP_NONE; |
42943cde | 583 | if (tnl_port_reconfigure(iter, iter->up.netdev, |
a36de779 PS |
584 | iter->odp_port, |
585 | ovs_native_tunneling_is_on(ofproto), dp_port)) { | |
a614d823 KM |
586 | backer->need_revalidate = REV_RECONFIGURE; |
587 | } | |
588 | } | |
589 | } | |
590 | ||
591 | SIMAP_FOR_EACH (node, &tmp_backers) { | |
4e022ec0 | 592 | dpif_port_del(backer->dpif, u32_to_odp(node->data)); |
a614d823 KM |
593 | } |
594 | simap_destroy(&tmp_backers); | |
2cc3c58e EJ |
595 | |
596 | switch (backer->need_revalidate) { | |
1373ee25 FL |
597 | case REV_RECONFIGURE: COVERAGE_INC(rev_reconfigure); break; |
598 | case REV_STP: COVERAGE_INC(rev_stp); break; | |
9efd308e | 599 | case REV_RSTP: COVERAGE_INC(rev_rstp); break; |
1373ee25 FL |
600 | case REV_BOND: COVERAGE_INC(rev_bond); break; |
601 | case REV_PORT_TOGGLED: COVERAGE_INC(rev_port_toggled); break; | |
602 | case REV_FLOW_TABLE: COVERAGE_INC(rev_flow_table); break; | |
603 | case REV_MAC_LEARNING: COVERAGE_INC(rev_mac_learning); break; | |
6d95c4e8 | 604 | case REV_MCAST_SNOOPING: COVERAGE_INC(rev_mcast_snooping); break; |
2cc3c58e | 605 | } |
f728af2e BP |
606 | backer->need_revalidate = 0; |
607 | ||
2cc3c58e | 608 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { |
a1616063 | 609 | struct ofport_dpif *ofport; |
a1616063 | 610 | struct ofbundle *bundle; |
2cc3c58e EJ |
611 | |
612 | if (ofproto->backer != backer) { | |
613 | continue; | |
614 | } | |
615 | ||
84f0f298 | 616 | xlate_txn_start(); |
89a8a7f0 | 617 | xlate_ofproto_set(ofproto, ofproto->up.name, |
34dd0d78 | 618 | ofproto->backer->dpif, ofproto->ml, |
9efd308e DV |
619 | ofproto->stp, ofproto->rstp, ofproto->ms, |
620 | ofproto->mbridge, ofproto->sflow, ofproto->ipfix, | |
2f47cdf4 | 621 | ofproto->netflow, |
a1616063 | 622 | ofproto->up.forward_bpdu, |
4b97b70d | 623 | connmgr_has_in_band(ofproto->up.connmgr), |
b440dd8c | 624 | &ofproto->backer->support); |
46c88433 | 625 | |
a1616063 EJ |
626 | HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) { |
627 | xlate_bundle_set(ofproto, bundle, bundle->name, | |
628 | bundle->vlan_mode, bundle->vlan, | |
629 | bundle->trunks, bundle->use_priority_tags, | |
630 | bundle->bond, bundle->lacp, | |
631 | bundle->floodable); | |
632 | } | |
633 | ||
634 | HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) { | |
9d189a50 EJ |
635 | int stp_port = ofport->stp_port |
636 | ? stp_port_no(ofport->stp_port) | |
92cf817b | 637 | : -1; |
a1616063 EJ |
638 | xlate_ofport_set(ofproto, ofport->bundle, ofport, |
639 | ofport->up.ofp_port, ofport->odp_port, | |
0477baa9 DF |
640 | ofport->up.netdev, ofport->cfm, ofport->bfd, |
641 | ofport->lldp, ofport->peer, stp_port, | |
f025bcb7 JR |
642 | ofport->rstp_port, ofport->qdscp, |
643 | ofport->n_qdscp, ofport->up.pp.config, | |
644 | ofport->up.pp.state, ofport->is_tunnel, | |
645 | ofport->may_enable); | |
46c88433 | 646 | } |
84f0f298 | 647 | xlate_txn_commit(); |
2cc3c58e | 648 | } |
e1ec7dd4 EJ |
649 | |
650 | udpif_revalidate(backer->udpif); | |
2cc3c58e EJ |
651 | } |
652 | ||
36beb9be | 653 | process_dpif_port_changes(backer); |
acf60855 JP |
654 | |
655 | return 0; | |
656 | } | |
657 | ||
36beb9be BP |
658 | /* Check for and handle port changes in 'backer''s dpif. */ |
659 | static void | |
660 | process_dpif_port_changes(struct dpif_backer *backer) | |
661 | { | |
662 | for (;;) { | |
663 | char *devname; | |
664 | int error; | |
665 | ||
666 | error = dpif_port_poll(backer->dpif, &devname); | |
667 | switch (error) { | |
668 | case EAGAIN: | |
669 | return; | |
670 | ||
671 | case ENOBUFS: | |
672 | process_dpif_all_ports_changed(backer); | |
673 | break; | |
674 | ||
675 | case 0: | |
676 | process_dpif_port_change(backer, devname); | |
677 | free(devname); | |
678 | break; | |
679 | ||
680 | default: | |
681 | process_dpif_port_error(backer, error); | |
682 | break; | |
683 | } | |
684 | } | |
685 | } | |
686 | ||
687 | static void | |
688 | process_dpif_all_ports_changed(struct dpif_backer *backer) | |
689 | { | |
690 | struct ofproto_dpif *ofproto; | |
691 | struct dpif_port dpif_port; | |
692 | struct dpif_port_dump dump; | |
693 | struct sset devnames; | |
694 | const char *devname; | |
695 | ||
696 | sset_init(&devnames); | |
697 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
698 | if (ofproto->backer == backer) { | |
699 | struct ofport *ofport; | |
700 | ||
701 | HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) { | |
702 | sset_add(&devnames, netdev_get_name(ofport->netdev)); | |
703 | } | |
704 | } | |
705 | } | |
706 | DPIF_PORT_FOR_EACH (&dpif_port, &dump, backer->dpif) { | |
707 | sset_add(&devnames, dpif_port.name); | |
708 | } | |
709 | ||
710 | SSET_FOR_EACH (devname, &devnames) { | |
711 | process_dpif_port_change(backer, devname); | |
712 | } | |
713 | sset_destroy(&devnames); | |
714 | } | |
715 | ||
716 | static void | |
717 | process_dpif_port_change(struct dpif_backer *backer, const char *devname) | |
718 | { | |
719 | struct ofproto_dpif *ofproto; | |
720 | struct dpif_port port; | |
721 | ||
722 | /* Don't report on the datapath's device. */ | |
723 | if (!strcmp(devname, dpif_base_name(backer->dpif))) { | |
724 | return; | |
725 | } | |
726 | ||
727 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, | |
728 | &all_ofproto_dpifs) { | |
729 | if (simap_contains(&ofproto->backer->tnl_backers, devname)) { | |
730 | return; | |
731 | } | |
732 | } | |
733 | ||
734 | ofproto = lookup_ofproto_dpif_by_port_name(devname); | |
735 | if (dpif_port_query_by_name(backer->dpif, devname, &port)) { | |
736 | /* The port was removed. If we know the datapath, | |
737 | * report it through poll_set(). If we don't, it may be | |
738 | * notifying us of a removal we initiated, so ignore it. | |
739 | * If there's a pending ENOBUFS, let it stand, since | |
740 | * everything will be reevaluated. */ | |
741 | if (ofproto && ofproto->port_poll_errno != ENOBUFS) { | |
742 | sset_add(&ofproto->port_poll_set, devname); | |
743 | ofproto->port_poll_errno = 0; | |
744 | } | |
745 | } else if (!ofproto) { | |
746 | /* The port was added, but we don't know with which | |
747 | * ofproto we should associate it. Delete it. */ | |
748 | dpif_port_del(backer->dpif, port.port_no); | |
74cc3969 BP |
749 | } else { |
750 | struct ofport_dpif *ofport; | |
751 | ||
752 | ofport = ofport_dpif_cast(shash_find_data( | |
753 | &ofproto->up.port_by_name, devname)); | |
754 | if (ofport | |
755 | && ofport->odp_port != port.port_no | |
756 | && !odp_port_to_ofport(backer, port.port_no)) | |
757 | { | |
758 | /* 'ofport''s datapath port number has changed from | |
759 | * 'ofport->odp_port' to 'port.port_no'. Update our internal data | |
760 | * structures to match. */ | |
8449c4d6 | 761 | ovs_rwlock_wrlock(&backer->odp_to_ofport_lock); |
74cc3969 BP |
762 | hmap_remove(&backer->odp_to_ofport_map, &ofport->odp_port_node); |
763 | ofport->odp_port = port.port_no; | |
764 | hmap_insert(&backer->odp_to_ofport_map, &ofport->odp_port_node, | |
765 | hash_odp_port(port.port_no)); | |
8449c4d6 | 766 | ovs_rwlock_unlock(&backer->odp_to_ofport_lock); |
74cc3969 BP |
767 | backer->need_revalidate = REV_RECONFIGURE; |
768 | } | |
36beb9be BP |
769 | } |
770 | dpif_port_destroy(&port); | |
771 | } | |
772 | ||
773 | /* Propagate 'error' to all ofprotos based on 'backer'. */ | |
774 | static void | |
775 | process_dpif_port_error(struct dpif_backer *backer, int error) | |
776 | { | |
777 | struct ofproto_dpif *ofproto; | |
778 | ||
779 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
780 | if (ofproto->backer == backer) { | |
781 | sset_clear(&ofproto->port_poll_set); | |
782 | ofproto->port_poll_errno = error; | |
783 | } | |
784 | } | |
785 | } | |
786 | ||
acf60855 JP |
787 | static void |
788 | type_wait(const char *type) | |
789 | { | |
790 | struct dpif_backer *backer; | |
791 | ||
792 | backer = shash_find_data(&all_dpif_backers, type); | |
793 | if (!backer) { | |
794 | /* This is not necessarily a problem, since backers are only | |
795 | * created on demand. */ | |
796 | return; | |
797 | } | |
798 | ||
c0365fc8 | 799 | dpif_wait(backer->dpif); |
acf60855 JP |
800 | } |
801 | \f | |
abe529af BP |
802 | /* Basic life-cycle. */ |
803 | ||
c57b2226 BP |
804 | static int add_internal_flows(struct ofproto_dpif *); |
805 | ||
abe529af BP |
806 | static struct ofproto * |
807 | alloc(void) | |
808 | { | |
3da29e32 | 809 | struct ofproto_dpif *ofproto = xzalloc(sizeof *ofproto); |
abe529af BP |
810 | return &ofproto->up; |
811 | } | |
812 | ||
813 | static void | |
814 | dealloc(struct ofproto *ofproto_) | |
815 | { | |
816 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
817 | free(ofproto); | |
818 | } | |
819 | ||
acf60855 JP |
820 | static void |
821 | close_dpif_backer(struct dpif_backer *backer) | |
822 | { | |
cb22974d | 823 | ovs_assert(backer->refcount > 0); |
acf60855 JP |
824 | |
825 | if (--backer->refcount) { | |
826 | return; | |
827 | } | |
828 | ||
b395cf1f BP |
829 | udpif_destroy(backer->udpif); |
830 | ||
7d82ab2e | 831 | simap_destroy(&backer->tnl_backers); |
8449c4d6 | 832 | ovs_rwlock_destroy(&backer->odp_to_ofport_lock); |
acf60855 | 833 | hmap_destroy(&backer->odp_to_ofport_map); |
4f7cc3c7 | 834 | shash_find_and_delete(&all_dpif_backers, backer->type); |
acf60855 | 835 | free(backer->type); |
b5cbbcf6 | 836 | free(backer->dp_version_string); |
acf60855 | 837 | dpif_close(backer->dpif); |
acf60855 JP |
838 | free(backer); |
839 | } | |
840 | ||
841 | /* Datapath port slated for removal from datapath. */ | |
842 | struct odp_garbage { | |
ca6ba700 | 843 | struct ovs_list list_node; |
4e022ec0 | 844 | odp_port_t odp_port; |
acf60855 JP |
845 | }; |
846 | ||
4b97b70d | 847 | static bool check_variable_length_userdata(struct dpif_backer *backer); |
b440dd8c | 848 | static void check_support(struct dpif_backer *backer); |
4b97b70d | 849 | |
acf60855 JP |
850 | static int |
851 | open_dpif_backer(const char *type, struct dpif_backer **backerp) | |
852 | { | |
853 | struct dpif_backer *backer; | |
854 | struct dpif_port_dump port_dump; | |
855 | struct dpif_port port; | |
856 | struct shash_node *node; | |
ca6ba700 | 857 | struct ovs_list garbage_list; |
5f03c983 | 858 | struct odp_garbage *garbage; |
f5374617 | 859 | |
acf60855 JP |
860 | struct sset names; |
861 | char *backer_name; | |
862 | const char *name; | |
863 | int error; | |
864 | ||
865 | backer = shash_find_data(&all_dpif_backers, type); | |
866 | if (backer) { | |
867 | backer->refcount++; | |
868 | *backerp = backer; | |
869 | return 0; | |
870 | } | |
871 | ||
872 | backer_name = xasprintf("ovs-%s", type); | |
873 | ||
874 | /* Remove any existing datapaths, since we assume we're the only | |
875 | * userspace controlling the datapath. */ | |
876 | sset_init(&names); | |
877 | dp_enumerate_names(type, &names); | |
878 | SSET_FOR_EACH(name, &names) { | |
879 | struct dpif *old_dpif; | |
880 | ||
881 | /* Don't remove our backer if it exists. */ | |
882 | if (!strcmp(name, backer_name)) { | |
883 | continue; | |
884 | } | |
885 | ||
886 | if (dpif_open(name, type, &old_dpif)) { | |
887 | VLOG_WARN("couldn't open old datapath %s to remove it", name); | |
888 | } else { | |
889 | dpif_delete(old_dpif); | |
890 | dpif_close(old_dpif); | |
891 | } | |
892 | } | |
893 | sset_destroy(&names); | |
894 | ||
895 | backer = xmalloc(sizeof *backer); | |
896 | ||
897 | error = dpif_create_and_open(backer_name, type, &backer->dpif); | |
898 | free(backer_name); | |
899 | if (error) { | |
900 | VLOG_ERR("failed to open datapath of type %s: %s", type, | |
10a89ef0 | 901 | ovs_strerror(error)); |
4c1b1289 | 902 | free(backer); |
acf60855 JP |
903 | return error; |
904 | } | |
e1ec7dd4 | 905 | backer->udpif = udpif_create(backer, backer->dpif); |
acf60855 JP |
906 | |
907 | backer->type = xstrdup(type); | |
908 | backer->refcount = 1; | |
909 | hmap_init(&backer->odp_to_ofport_map); | |
8449c4d6 | 910 | ovs_rwlock_init(&backer->odp_to_ofport_lock); |
2cc3c58e | 911 | backer->need_revalidate = 0; |
7d82ab2e | 912 | simap_init(&backer->tnl_backers); |
40358701 | 913 | backer->recv_set_enable = !ofproto_get_flow_restore_wait(); |
acf60855 JP |
914 | *backerp = backer; |
915 | ||
40358701 GS |
916 | if (backer->recv_set_enable) { |
917 | dpif_flow_flush(backer->dpif); | |
918 | } | |
acf60855 JP |
919 | |
920 | /* Loop through the ports already on the datapath and remove any | |
921 | * that we don't need anymore. */ | |
417e7e66 | 922 | ovs_list_init(&garbage_list); |
acf60855 JP |
923 | dpif_port_dump_start(&port_dump, backer->dpif); |
924 | while (dpif_port_dump_next(&port_dump, &port)) { | |
925 | node = shash_find(&init_ofp_ports, port.name); | |
926 | if (!node && strcmp(port.name, dpif_base_name(backer->dpif))) { | |
927 | garbage = xmalloc(sizeof *garbage); | |
928 | garbage->odp_port = port.port_no; | |
417e7e66 | 929 | ovs_list_push_front(&garbage_list, &garbage->list_node); |
acf60855 JP |
930 | } |
931 | } | |
932 | dpif_port_dump_done(&port_dump); | |
933 | ||
5f03c983 | 934 | LIST_FOR_EACH_POP (garbage, list_node, &garbage_list) { |
acf60855 | 935 | dpif_port_del(backer->dpif, garbage->odp_port); |
acf60855 JP |
936 | free(garbage); |
937 | } | |
938 | ||
939 | shash_add(&all_dpif_backers, type, backer); | |
940 | ||
b440dd8c | 941 | check_support(backer); |
a36de779 PS |
942 | atomic_count_init(&backer->tnl_count, 0); |
943 | ||
40358701 | 944 | error = dpif_recv_set(backer->dpif, backer->recv_set_enable); |
acf60855 JP |
945 | if (error) { |
946 | VLOG_ERR("failed to listen on datapath of type %s: %s", | |
10a89ef0 | 947 | type, ovs_strerror(error)); |
acf60855 JP |
948 | close_dpif_backer(backer); |
949 | return error; | |
950 | } | |
6567010f EJ |
951 | |
952 | if (backer->recv_set_enable) { | |
e79a6c83 | 953 | udpif_set_threads(backer->udpif, n_handlers, n_revalidators); |
6567010f | 954 | } |
acf60855 | 955 | |
48931b58 JR |
956 | /* This check fails if performed before udpif threads have been set, |
957 | * as the kernel module checks that the 'pid' in userspace action | |
958 | * is non-zero. */ | |
b440dd8c JS |
959 | backer->support.variable_length_userdata |
960 | = check_variable_length_userdata(backer); | |
b5cbbcf6 | 961 | backer->dp_version_string = dpif_get_dp_version(backer->dpif); |
48931b58 | 962 | |
acf60855 JP |
963 | return error; |
964 | } | |
965 | ||
a36de779 PS |
966 | bool |
967 | ovs_native_tunneling_is_on(struct ofproto_dpif *ofproto) | |
968 | { | |
b440dd8c | 969 | return ofproto_use_tnl_push_pop && ofproto->backer->support.tnl_push_pop && |
a36de779 PS |
970 | atomic_count_get(&ofproto->backer->tnl_count); |
971 | } | |
972 | ||
9b2cb971 SH |
973 | /* Tests whether 'backer''s datapath supports recirculation. Only newer |
974 | * datapaths support OVS_KEY_ATTR_RECIRC_ID in keys. We need to disable some | |
975 | * features on older datapaths that don't support this feature. | |
adcf00ba AZ |
976 | * |
977 | * Returns false if 'backer' definitely does not support recirculation, true if | |
978 | * it seems to support recirculation or if at least the error we get is | |
979 | * ambiguous. */ | |
980 | static bool | |
981 | check_recirc(struct dpif_backer *backer) | |
982 | { | |
983 | struct flow flow; | |
984 | struct odputil_keybuf keybuf; | |
985 | struct ofpbuf key; | |
2c85851f | 986 | bool enable_recirc; |
5262eea1 JG |
987 | struct odp_flow_key_parms odp_parms = { |
988 | .flow = &flow, | |
2494ccd7 JS |
989 | .support = { |
990 | .recirc = true, | |
991 | }, | |
5262eea1 | 992 | }; |
adcf00ba AZ |
993 | |
994 | memset(&flow, 0, sizeof flow); | |
995 | flow.recirc_id = 1; | |
996 | flow.dp_hash = 1; | |
997 | ||
998 | ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); | |
5262eea1 | 999 | odp_flow_key_from_flow(&odp_parms, &key); |
2c85851f JS |
1000 | enable_recirc = dpif_probe_feature(backer->dpif, "recirculation", &key, |
1001 | NULL); | |
adcf00ba | 1002 | |
adcf00ba AZ |
1003 | if (enable_recirc) { |
1004 | VLOG_INFO("%s: Datapath supports recirculation", | |
1005 | dpif_name(backer->dpif)); | |
1006 | } else { | |
1007 | VLOG_INFO("%s: Datapath does not support recirculation", | |
1008 | dpif_name(backer->dpif)); | |
1009 | } | |
1010 | ||
1011 | return enable_recirc; | |
1012 | } | |
1013 | ||
7915c9d6 | 1014 | /* Tests whether 'dpif' supports unique flow ids. We can skip serializing |
8e1ffd75 JS |
1015 | * some flow attributes for datapaths that support this feature. |
1016 | * | |
1017 | * Returns true if 'dpif' supports UFID for flow operations. | |
1018 | * Returns false if 'dpif' does not support UFID. */ | |
1019 | static bool | |
1020 | check_ufid(struct dpif_backer *backer) | |
1021 | { | |
1022 | struct flow flow; | |
1023 | struct odputil_keybuf keybuf; | |
1024 | struct ofpbuf key; | |
1025 | ovs_u128 ufid; | |
1026 | bool enable_ufid; | |
5262eea1 JG |
1027 | struct odp_flow_key_parms odp_parms = { |
1028 | .flow = &flow, | |
1029 | }; | |
8e1ffd75 JS |
1030 | |
1031 | memset(&flow, 0, sizeof flow); | |
1032 | flow.dl_type = htons(0x1234); | |
1033 | ||
1034 | ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); | |
5262eea1 | 1035 | odp_flow_key_from_flow(&odp_parms, &key); |
6fd6ed71 | 1036 | dpif_flow_hash(backer->dpif, key.data, key.size, &ufid); |
8e1ffd75 JS |
1037 | |
1038 | enable_ufid = dpif_probe_feature(backer->dpif, "UFID", &key, &ufid); | |
1039 | ||
1040 | if (enable_ufid) { | |
7915c9d6 | 1041 | VLOG_INFO("%s: Datapath supports unique flow ids", |
8e1ffd75 JS |
1042 | dpif_name(backer->dpif)); |
1043 | } else { | |
7915c9d6 | 1044 | VLOG_INFO("%s: Datapath does not support unique flow ids", |
8e1ffd75 JS |
1045 | dpif_name(backer->dpif)); |
1046 | } | |
1047 | return enable_ufid; | |
1048 | } | |
1049 | ||
4b97b70d BP |
1050 | /* Tests whether 'backer''s datapath supports variable-length |
1051 | * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. We need | |
1052 | * to disable some features on older datapaths that don't support this | |
1053 | * feature. | |
1054 | * | |
1055 | * Returns false if 'backer' definitely does not support variable-length | |
1056 | * userdata, true if it seems to support them or if at least the error we get | |
1057 | * is ambiguous. */ | |
1058 | static bool | |
1059 | check_variable_length_userdata(struct dpif_backer *backer) | |
1060 | { | |
1061 | struct eth_header *eth; | |
1062 | struct ofpbuf actions; | |
758c456d | 1063 | struct dpif_execute execute; |
cf62fa4c | 1064 | struct dp_packet packet; |
1cceb31b | 1065 | struct flow flow; |
4b97b70d BP |
1066 | size_t start; |
1067 | int error; | |
1068 | ||
1069 | /* Compose a userspace action that will cause an ERANGE error on older | |
1070 | * datapaths that don't support variable-length userdata. | |
1071 | * | |
1072 | * We really test for using userdata longer than 8 bytes, but older | |
1073 | * datapaths accepted these, silently truncating the userdata to 8 bytes. | |
1074 | * The same older datapaths rejected userdata shorter than 8 bytes, so we | |
1075 | * test for that instead as a proxy for longer userdata support. */ | |
1076 | ofpbuf_init(&actions, 64); | |
1077 | start = nl_msg_start_nested(&actions, OVS_ACTION_ATTR_USERSPACE); | |
1078 | nl_msg_put_u32(&actions, OVS_USERSPACE_ATTR_PID, | |
1954e6bb | 1079 | dpif_port_get_pid(backer->dpif, ODPP_NONE, 0)); |
4b97b70d BP |
1080 | nl_msg_put_unspec_zero(&actions, OVS_USERSPACE_ATTR_USERDATA, 4); |
1081 | nl_msg_end_nested(&actions, start); | |
1082 | ||
758c456d | 1083 | /* Compose a dummy ethernet packet. */ |
cf62fa4c PS |
1084 | dp_packet_init(&packet, ETH_HEADER_LEN); |
1085 | eth = dp_packet_put_zeros(&packet, ETH_HEADER_LEN); | |
4b97b70d BP |
1086 | eth->eth_type = htons(0x1234); |
1087 | ||
1cceb31b DDP |
1088 | flow_extract(&packet, &flow); |
1089 | ||
758c456d | 1090 | /* Execute the actions. On older datapaths this fails with ERANGE, on |
4b97b70d | 1091 | * newer datapaths it succeeds. */ |
6fd6ed71 PS |
1092 | execute.actions = actions.data; |
1093 | execute.actions_len = actions.size; | |
758c456d | 1094 | execute.packet = &packet; |
1cceb31b | 1095 | execute.flow = &flow; |
758c456d | 1096 | execute.needs_help = false; |
43f9ac0a | 1097 | execute.probe = true; |
27130224 | 1098 | execute.mtu = 0; |
758c456d JR |
1099 | |
1100 | error = dpif_execute(backer->dpif, &execute); | |
4b97b70d | 1101 | |
cf62fa4c | 1102 | dp_packet_uninit(&packet); |
4b97b70d BP |
1103 | ofpbuf_uninit(&actions); |
1104 | ||
1105 | switch (error) { | |
1106 | case 0: | |
4b97b70d BP |
1107 | return true; |
1108 | ||
1109 | case ERANGE: | |
1110 | /* Variable-length userdata is not supported. */ | |
1111 | VLOG_WARN("%s: datapath does not support variable-length userdata " | |
1112 | "feature (needs Linux 3.10+ or kernel module from OVS " | |
1113 | "1..11+). The NXAST_SAMPLE action will be ignored.", | |
1114 | dpif_name(backer->dpif)); | |
1115 | return false; | |
1116 | ||
1117 | default: | |
1118 | /* Something odd happened. We're not sure whether variable-length | |
1119 | * userdata is supported. Default to "yes". */ | |
1120 | VLOG_WARN("%s: variable-length userdata feature probe failed (%s)", | |
1121 | dpif_name(backer->dpif), ovs_strerror(error)); | |
1122 | return true; | |
1123 | } | |
1124 | } | |
1125 | ||
8bfd0fda BP |
1126 | /* Tests the MPLS label stack depth supported by 'backer''s datapath. |
1127 | * | |
1128 | * Returns the number of elements in a struct flow's mpls_lse field | |
1129 | * if the datapath supports at least that many entries in an | |
1130 | * MPLS label stack. | |
1131 | * Otherwise returns the number of MPLS push actions supported by | |
1132 | * the datapath. */ | |
1133 | static size_t | |
1134 | check_max_mpls_depth(struct dpif_backer *backer) | |
1135 | { | |
1136 | struct flow flow; | |
1137 | int n; | |
1138 | ||
1139 | for (n = 0; n < FLOW_MAX_MPLS_LABELS; n++) { | |
1140 | struct odputil_keybuf keybuf; | |
1141 | struct ofpbuf key; | |
5262eea1 JG |
1142 | struct odp_flow_key_parms odp_parms = { |
1143 | .flow = &flow, | |
1144 | }; | |
8bfd0fda BP |
1145 | |
1146 | memset(&flow, 0, sizeof flow); | |
1147 | flow.dl_type = htons(ETH_TYPE_MPLS); | |
1148 | flow_set_mpls_bos(&flow, n, 1); | |
1149 | ||
1150 | ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); | |
5262eea1 | 1151 | odp_flow_key_from_flow(&odp_parms, &key); |
2c85851f | 1152 | if (!dpif_probe_feature(backer->dpif, "MPLS", &key, NULL)) { |
8bfd0fda BP |
1153 | break; |
1154 | } | |
8bfd0fda BP |
1155 | } |
1156 | ||
1157 | VLOG_INFO("%s: MPLS label stack length probed as %d", | |
1158 | dpif_name(backer->dpif), n); | |
1159 | return n; | |
1160 | } | |
1161 | ||
53477c2c JR |
1162 | /* Tests whether 'backer''s datapath supports masked data in |
1163 | * OVS_ACTION_ATTR_SET actions. We need to disable some features on older | |
1164 | * datapaths that don't support this feature. */ | |
1165 | static bool | |
1166 | check_masked_set_action(struct dpif_backer *backer) | |
1167 | { | |
1168 | struct eth_header *eth; | |
1169 | struct ofpbuf actions; | |
1170 | struct dpif_execute execute; | |
cf62fa4c | 1171 | struct dp_packet packet; |
1cceb31b | 1172 | struct flow flow; |
53477c2c JR |
1173 | int error; |
1174 | struct ovs_key_ethernet key, mask; | |
1175 | ||
1176 | /* Compose a set action that will cause an EINVAL error on older | |
1177 | * datapaths that don't support masked set actions. | |
1178 | * Avoid using a full mask, as it could be translated to a non-masked | |
1179 | * set action instead. */ | |
1180 | ofpbuf_init(&actions, 64); | |
1181 | memset(&key, 0x53, sizeof key); | |
1182 | memset(&mask, 0x7f, sizeof mask); | |
1183 | commit_masked_set_action(&actions, OVS_KEY_ATTR_ETHERNET, &key, &mask, | |
1184 | sizeof key); | |
1185 | ||
1186 | /* Compose a dummy ethernet packet. */ | |
cf62fa4c PS |
1187 | dp_packet_init(&packet, ETH_HEADER_LEN); |
1188 | eth = dp_packet_put_zeros(&packet, ETH_HEADER_LEN); | |
53477c2c JR |
1189 | eth->eth_type = htons(0x1234); |
1190 | ||
1cceb31b DDP |
1191 | flow_extract(&packet, &flow); |
1192 | ||
53477c2c JR |
1193 | /* Execute the actions. On older datapaths this fails with EINVAL, on |
1194 | * newer datapaths it succeeds. */ | |
6fd6ed71 PS |
1195 | execute.actions = actions.data; |
1196 | execute.actions_len = actions.size; | |
53477c2c | 1197 | execute.packet = &packet; |
1cceb31b | 1198 | execute.flow = &flow; |
53477c2c | 1199 | execute.needs_help = false; |
43f9ac0a | 1200 | execute.probe = true; |
27130224 | 1201 | execute.mtu = 0; |
53477c2c JR |
1202 | |
1203 | error = dpif_execute(backer->dpif, &execute); | |
1204 | ||
cf62fa4c | 1205 | dp_packet_uninit(&packet); |
53477c2c JR |
1206 | ofpbuf_uninit(&actions); |
1207 | ||
1208 | if (error) { | |
1209 | /* Masked set action is not supported. */ | |
1210 | VLOG_INFO("%s: datapath does not support masked set action feature.", | |
1211 | dpif_name(backer->dpif)); | |
1212 | } | |
1213 | return !error; | |
1214 | } | |
1215 | ||
aaca4fe0 WT |
1216 | /* Tests whether 'backer''s datapath supports truncation of a packet in |
1217 | * OVS_ACTION_ATTR_TRUNC. We need to disable some features on older | |
1218 | * datapaths that don't support this feature. */ | |
1219 | static bool | |
1220 | check_trunc_action(struct dpif_backer *backer) | |
1221 | { | |
1222 | struct eth_header *eth; | |
1223 | struct ofpbuf actions; | |
1224 | struct dpif_execute execute; | |
1225 | struct dp_packet packet; | |
1226 | struct ovs_action_trunc *trunc; | |
1227 | struct flow flow; | |
1228 | int error; | |
1229 | ||
1230 | /* Compose an action with output(port:1, | |
1231 | * max_len:OVS_ACTION_OUTPUT_MIN + 1). | |
1232 | * This translates to one truncate action and one output action. */ | |
1233 | ofpbuf_init(&actions, 64); | |
1234 | trunc = nl_msg_put_unspec_uninit(&actions, | |
1235 | OVS_ACTION_ATTR_TRUNC, sizeof *trunc); | |
1236 | ||
1237 | trunc->max_len = ETH_HEADER_LEN + 1; | |
1238 | nl_msg_put_odp_port(&actions, OVS_ACTION_ATTR_OUTPUT, u32_to_odp(1)); | |
1239 | ||
1240 | /* Compose a dummy Ethernet packet. */ | |
1241 | dp_packet_init(&packet, ETH_HEADER_LEN); | |
1242 | eth = dp_packet_put_zeros(&packet, ETH_HEADER_LEN); | |
1243 | eth->eth_type = htons(0x1234); | |
1244 | ||
1245 | flow_extract(&packet, &flow); | |
1246 | ||
1247 | /* Execute the actions. On older datapaths this fails with EINVAL, on | |
1248 | * newer datapaths it succeeds. */ | |
1249 | execute.actions = actions.data; | |
1250 | execute.actions_len = actions.size; | |
1251 | execute.packet = &packet; | |
1252 | execute.flow = &flow; | |
1253 | execute.needs_help = false; | |
1254 | execute.probe = true; | |
1255 | execute.mtu = 0; | |
1256 | ||
1257 | error = dpif_execute(backer->dpif, &execute); | |
1258 | ||
1259 | dp_packet_uninit(&packet); | |
1260 | ofpbuf_uninit(&actions); | |
1261 | ||
1262 | if (error) { | |
1263 | VLOG_INFO("%s: Datapath does not support truncate action", | |
1264 | dpif_name(backer->dpif)); | |
1265 | } else { | |
1266 | VLOG_INFO("%s: Datapath supports truncate action", | |
1267 | dpif_name(backer->dpif)); | |
1268 | } | |
1269 | ||
1270 | return !error; | |
1271 | } | |
1272 | ||
7b27258c | 1273 | #define CHECK_FEATURE__(NAME, SUPPORT, FIELD, VALUE) \ |
07659514 JS |
1274 | static bool \ |
1275 | check_##NAME(struct dpif_backer *backer) \ | |
1276 | { \ | |
1277 | struct flow flow; \ | |
1278 | struct odputil_keybuf keybuf; \ | |
1279 | struct ofpbuf key; \ | |
1280 | bool enable; \ | |
1281 | struct odp_flow_key_parms odp_parms = { \ | |
1282 | .flow = &flow, \ | |
1283 | .support = { \ | |
7b27258c | 1284 | .SUPPORT = true, \ |
07659514 JS |
1285 | }, \ |
1286 | }; \ | |
1287 | \ | |
1288 | memset(&flow, 0, sizeof flow); \ | |
7b27258c | 1289 | flow.FIELD = VALUE; \ |
07659514 JS |
1290 | \ |
1291 | ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); \ | |
1292 | odp_flow_key_from_flow(&odp_parms, &key); \ | |
1293 | enable = dpif_probe_feature(backer->dpif, #NAME, &key, NULL); \ | |
1294 | \ | |
1295 | if (enable) { \ | |
1296 | VLOG_INFO("%s: Datapath supports "#NAME, dpif_name(backer->dpif)); \ | |
1297 | } else { \ | |
1298 | VLOG_INFO("%s: Datapath does not support "#NAME, \ | |
1299 | dpif_name(backer->dpif)); \ | |
1300 | } \ | |
1301 | \ | |
1302 | return enable; \ | |
1303 | } | |
7b27258c | 1304 | #define CHECK_FEATURE(FIELD) CHECK_FEATURE__(FIELD, FIELD, FIELD, 1) |
07659514 JS |
1305 | |
1306 | CHECK_FEATURE(ct_state) | |
1307 | CHECK_FEATURE(ct_zone) | |
8e53fe8c | 1308 | CHECK_FEATURE(ct_mark) |
7b27258c DDP |
1309 | CHECK_FEATURE__(ct_label, ct_label, ct_label.u64.lo, 1) |
1310 | CHECK_FEATURE__(ct_state_nat, ct_state, ct_state, CS_TRACKED|CS_SRC_NAT) | |
07659514 JS |
1311 | |
1312 | #undef CHECK_FEATURE | |
1313 | #undef CHECK_FEATURE__ | |
1314 | ||
b440dd8c JS |
1315 | static void |
1316 | check_support(struct dpif_backer *backer) | |
1317 | { | |
1318 | /* This feature needs to be tested after udpif threads are set. */ | |
1319 | backer->support.variable_length_userdata = false; | |
1320 | ||
2494ccd7 JS |
1321 | backer->support.odp.recirc = check_recirc(backer); |
1322 | backer->support.odp.max_mpls_depth = check_max_mpls_depth(backer); | |
b440dd8c | 1323 | backer->support.masked_set_action = check_masked_set_action(backer); |
aaca4fe0 | 1324 | backer->support.trunc = check_trunc_action(backer); |
b440dd8c JS |
1325 | backer->support.ufid = check_ufid(backer); |
1326 | backer->support.tnl_push_pop = dpif_supports_tnl_push_pop(backer->dpif); | |
07659514 JS |
1327 | |
1328 | backer->support.odp.ct_state = check_ct_state(backer); | |
1329 | backer->support.odp.ct_zone = check_ct_zone(backer); | |
8e53fe8c | 1330 | backer->support.odp.ct_mark = check_ct_mark(backer); |
9daf2348 | 1331 | backer->support.odp.ct_label = check_ct_label(backer); |
7b27258c DDP |
1332 | |
1333 | backer->support.odp.ct_state_nat = check_ct_state_nat(backer); | |
b440dd8c JS |
1334 | } |
1335 | ||
abe529af | 1336 | static int |
0f5f95a9 | 1337 | construct(struct ofproto *ofproto_) |
abe529af BP |
1338 | { |
1339 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
acf60855 | 1340 | struct shash_node *node, *next; |
abe529af | 1341 | int error; |
abe529af | 1342 | |
4d9226a7 JR |
1343 | /* Tunnel module can get used right after the udpif threads are running. */ |
1344 | ofproto_tunnel_init(); | |
1345 | ||
acf60855 | 1346 | error = open_dpif_backer(ofproto->up.type, &ofproto->backer); |
abe529af | 1347 | if (error) { |
abe529af BP |
1348 | return error; |
1349 | } | |
1350 | ||
290835f9 | 1351 | uuid_generate(&ofproto->uuid); |
44e0c35d | 1352 | atomic_init(&ofproto->tables_version, OVS_VERSION_MIN); |
abe529af BP |
1353 | ofproto->netflow = NULL; |
1354 | ofproto->sflow = NULL; | |
29089a54 | 1355 | ofproto->ipfix = NULL; |
21f7563c | 1356 | ofproto->stp = NULL; |
9efd308e | 1357 | ofproto->rstp = NULL; |
e79a6c83 | 1358 | ofproto->dump_seq = 0; |
abe529af | 1359 | hmap_init(&ofproto->bundles); |
e764773c | 1360 | ofproto->ml = mac_learning_create(MAC_ENTRY_DEFAULT_IDLE_TIME); |
6d95c4e8 | 1361 | ofproto->ms = NULL; |
ec7ceaed | 1362 | ofproto->mbridge = mbridge_create(); |
abe529af | 1363 | ofproto->has_bonded_bundles = false; |
e2d13c43 | 1364 | ofproto->lacp_enabled = false; |
97ba2d36 | 1365 | ovs_mutex_init_adaptive(&ofproto->stats_mutex); |
abe529af | 1366 | |
a2b53dec | 1367 | guarded_list_init(&ofproto->ams); |
ada3a58d | 1368 | |
acf60855 | 1369 | sset_init(&ofproto->ports); |
0a740f48 | 1370 | sset_init(&ofproto->ghost_ports); |
acf60855 JP |
1371 | sset_init(&ofproto->port_poll_set); |
1372 | ofproto->port_poll_errno = 0; | |
f23d157c | 1373 | ofproto->change_seq = 0; |
a2b53dec BP |
1374 | ofproto->ams_seq = seq_create(); |
1375 | ofproto->ams_seqno = seq_read(ofproto->ams_seq); | |
cfc50ae5 | 1376 | |
acf60855 JP |
1377 | |
1378 | SHASH_FOR_EACH_SAFE (node, next, &init_ofp_ports) { | |
4f9e08a5 | 1379 | struct iface_hint *iface_hint = node->data; |
acf60855 JP |
1380 | |
1381 | if (!strcmp(iface_hint->br_name, ofproto->up.name)) { | |
1382 | /* Check if the datapath already has this port. */ | |
1383 | if (dpif_port_exists(ofproto->backer->dpif, node->name)) { | |
1384 | sset_add(&ofproto->ports, node->name); | |
1385 | } | |
1386 | ||
1387 | free(iface_hint->br_name); | |
1388 | free(iface_hint->br_type); | |
4f9e08a5 | 1389 | free(iface_hint); |
acf60855 JP |
1390 | shash_delete(&init_ofp_ports, node); |
1391 | } | |
1392 | } | |
e1b1d06a | 1393 | |
b44a10b7 BP |
1394 | hmap_insert(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node, |
1395 | hash_string(ofproto->up.name, 0)); | |
6527c598 | 1396 | memset(&ofproto->stats, 0, sizeof ofproto->stats); |
0f5f95a9 BP |
1397 | |
1398 | ofproto_init_tables(ofproto_, N_TABLES); | |
c57b2226 | 1399 | error = add_internal_flows(ofproto); |
adcf00ba | 1400 | |
c57b2226 BP |
1401 | ofproto->up.tables[TBL_INTERNAL].flags = OFTABLE_HIDDEN | OFTABLE_READONLY; |
1402 | ||
1403 | return error; | |
1404 | } | |
1405 | ||
1406 | static int | |
adcf00ba | 1407 | add_internal_miss_flow(struct ofproto_dpif *ofproto, int id, |
f25d0cf3 | 1408 | const struct ofpbuf *ofpacts, struct rule_dpif **rulep) |
c57b2226 | 1409 | { |
adcf00ba | 1410 | struct match match; |
c57b2226 | 1411 | int error; |
adcf00ba | 1412 | struct rule *rule; |
c57b2226 | 1413 | |
adcf00ba AZ |
1414 | match_init_catchall(&match); |
1415 | match_set_reg(&match, 0, id); | |
c57b2226 | 1416 | |
290ad78a SH |
1417 | error = ofproto_dpif_add_internal_flow(ofproto, &match, 0, 0, ofpacts, |
1418 | &rule); | |
adcf00ba | 1419 | *rulep = error ? NULL : rule_dpif_cast(rule); |
0f5f95a9 | 1420 | |
adcf00ba | 1421 | return error; |
abe529af BP |
1422 | } |
1423 | ||
c57b2226 BP |
1424 | static int |
1425 | add_internal_flows(struct ofproto_dpif *ofproto) | |
1426 | { | |
f25d0cf3 BP |
1427 | struct ofpact_controller *controller; |
1428 | uint64_t ofpacts_stub[128 / 8]; | |
1429 | struct ofpbuf ofpacts; | |
adcf00ba | 1430 | struct rule *unused_rulep OVS_UNUSED; |
adcf00ba | 1431 | struct match match; |
c57b2226 BP |
1432 | int error; |
1433 | int id; | |
1434 | ||
f25d0cf3 | 1435 | ofpbuf_use_stack(&ofpacts, ofpacts_stub, sizeof ofpacts_stub); |
c57b2226 BP |
1436 | id = 1; |
1437 | ||
f25d0cf3 BP |
1438 | controller = ofpact_put_CONTROLLER(&ofpacts); |
1439 | controller->max_len = UINT16_MAX; | |
1440 | controller->controller_id = 0; | |
9bfe9334 | 1441 | controller->reason = OFPR_IMPLICIT_MISS; |
ce058104 | 1442 | ofpact_finish_CONTROLLER(&ofpacts, &controller); |
f25d0cf3 | 1443 | |
adcf00ba AZ |
1444 | error = add_internal_miss_flow(ofproto, id++, &ofpacts, |
1445 | &ofproto->miss_rule); | |
c57b2226 BP |
1446 | if (error) { |
1447 | return error; | |
1448 | } | |
1449 | ||
f25d0cf3 | 1450 | ofpbuf_clear(&ofpacts); |
adcf00ba | 1451 | error = add_internal_miss_flow(ofproto, id++, &ofpacts, |
dbb7c28f | 1452 | &ofproto->no_packet_in_rule); |
7fd51d39 BP |
1453 | if (error) { |
1454 | return error; | |
1455 | } | |
1456 | ||
adcf00ba | 1457 | error = add_internal_miss_flow(ofproto, id++, &ofpacts, |
dbb7c28f | 1458 | &ofproto->drop_frags_rule); |
adcf00ba AZ |
1459 | if (error) { |
1460 | return error; | |
1461 | } | |
1462 | ||
0c7812e5 AW |
1463 | /* Drop any run away non-recirc rule lookups. Recirc_id has to be |
1464 | * zero when reaching this rule. | |
adcf00ba | 1465 | * |
0c7812e5 | 1466 | * (priority=2), recirc_id=0, actions=drop |
adcf00ba | 1467 | */ |
0c7812e5 | 1468 | ofpbuf_clear(&ofpacts); |
adcf00ba AZ |
1469 | match_init_catchall(&match); |
1470 | match_set_recirc_id(&match, 0); | |
290ad78a | 1471 | error = ofproto_dpif_add_internal_flow(ofproto, &match, 2, 0, &ofpacts, |
adcf00ba | 1472 | &unused_rulep); |
c57b2226 BP |
1473 | return error; |
1474 | } | |
1475 | ||
abe529af BP |
1476 | static void |
1477 | destruct(struct ofproto *ofproto_) | |
1478 | { | |
1479 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
a2b53dec | 1480 | struct ofproto_async_msg *am; |
78c8df12 | 1481 | struct rule_dpif *rule; |
d0918789 | 1482 | struct oftable *table; |
a2b53dec | 1483 | struct ovs_list ams; |
abe529af | 1484 | |
875b94ed | 1485 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
84f0f298 | 1486 | xlate_txn_start(); |
46c88433 | 1487 | xlate_remove_ofproto(ofproto); |
84f0f298 | 1488 | xlate_txn_commit(); |
46c88433 | 1489 | |
3f142f59 BP |
1490 | /* Ensure that the upcall processing threads have no remaining references |
1491 | * to the ofproto or anything in it. */ | |
1492 | udpif_synchronize(ofproto->backer->udpif); | |
1fe409d5 | 1493 | |
b44a10b7 | 1494 | hmap_remove(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node); |
7ee20df1 | 1495 | |
0697b5c3 | 1496 | OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) { |
de4ad4a2 | 1497 | CLS_FOR_EACH (rule, up.cr, &table->cls) { |
8b81d1ef | 1498 | ofproto_rule_delete(&ofproto->up, &rule->up); |
0697b5c3 | 1499 | } |
7ee20df1 | 1500 | } |
daab0ae6 | 1501 | ofproto_group_delete_all(&ofproto->up); |
7ee20df1 | 1502 | |
a2b53dec BP |
1503 | guarded_list_pop_all(&ofproto->ams, &ams); |
1504 | LIST_FOR_EACH_POP (am, list_node, &ams) { | |
1505 | ofproto_async_msg_free(am); | |
ada3a58d | 1506 | } |
a2b53dec | 1507 | guarded_list_destroy(&ofproto->ams); |
ada3a58d | 1508 | |
e672ff9b | 1509 | recirc_free_ofproto(ofproto, ofproto->up.name); |
f9038ef6 | 1510 | |
ec7ceaed | 1511 | mbridge_unref(ofproto->mbridge); |
abe529af | 1512 | |
8e407f27 | 1513 | netflow_unref(ofproto->netflow); |
9723bcce | 1514 | dpif_sflow_unref(ofproto->sflow); |
8b7ea2d4 | 1515 | dpif_ipfix_unref(ofproto->ipfix); |
abe529af | 1516 | hmap_destroy(&ofproto->bundles); |
5d989517 | 1517 | mac_learning_unref(ofproto->ml); |
6d95c4e8 | 1518 | mcast_snooping_unref(ofproto->ms); |
abe529af | 1519 | |
acf60855 | 1520 | sset_destroy(&ofproto->ports); |
0a740f48 | 1521 | sset_destroy(&ofproto->ghost_ports); |
acf60855 | 1522 | sset_destroy(&ofproto->port_poll_set); |
e1b1d06a | 1523 | |
0da3c61b | 1524 | ovs_mutex_destroy(&ofproto->stats_mutex); |
13501305 | 1525 | |
a2b53dec | 1526 | seq_destroy(ofproto->ams_seq); |
cfc50ae5 | 1527 | |
acf60855 | 1528 | close_dpif_backer(ofproto->backer); |
abe529af BP |
1529 | } |
1530 | ||
5fcc0d00 BP |
1531 | static int |
1532 | run(struct ofproto *ofproto_) | |
1533 | { | |
1534 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
e79a6c83 | 1535 | uint64_t new_seq, new_dump_seq; |
5fcc0d00 | 1536 | |
ec7ceaed EJ |
1537 | if (mbridge_need_revalidate(ofproto->mbridge)) { |
1538 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
509c0149 | 1539 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
30618594 | 1540 | mac_learning_flush(ofproto->ml); |
509c0149 | 1541 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
6d95c4e8 | 1542 | mcast_snooping_mdb_flush(ofproto->ms); |
ec7ceaed EJ |
1543 | } |
1544 | ||
a2b53dec | 1545 | /* Always updates the ofproto->ams_seqno to avoid frequent wakeup during |
b53d5c33 | 1546 | * flow restore. Even though nothing is processed during flow restore, |
a2b53dec | 1547 | * all queued 'ams' will be handled immediately when flow restore |
b53d5c33 | 1548 | * completes. */ |
a2b53dec | 1549 | ofproto->ams_seqno = seq_read(ofproto->ams_seq); |
b53d5c33 | 1550 | |
a6b7506d | 1551 | /* Do not perform any periodic activity required by 'ofproto' while |
40358701 | 1552 | * waiting for flow restore to complete. */ |
a6b7506d | 1553 | if (!ofproto_get_flow_restore_wait()) { |
a2b53dec BP |
1554 | struct ofproto_async_msg *am; |
1555 | struct ovs_list ams; | |
1556 | ||
1557 | guarded_list_pop_all(&ofproto->ams, &ams); | |
1558 | LIST_FOR_EACH_POP (am, list_node, &ams) { | |
1559 | connmgr_send_async_msg(ofproto->up.connmgr, am); | |
1560 | ofproto_async_msg_free(am); | |
a6b7506d | 1561 | } |
abe529af BP |
1562 | } |
1563 | ||
abe529af | 1564 | if (ofproto->netflow) { |
8bfaca5b | 1565 | netflow_run(ofproto->netflow); |
abe529af BP |
1566 | } |
1567 | if (ofproto->sflow) { | |
bae473fe | 1568 | dpif_sflow_run(ofproto->sflow); |
abe529af | 1569 | } |
978427a5 RL |
1570 | if (ofproto->ipfix) { |
1571 | dpif_ipfix_run(ofproto->ipfix); | |
1572 | } | |
abe529af | 1573 | |
f23d157c JS |
1574 | new_seq = seq_read(connectivity_seq_get()); |
1575 | if (ofproto->change_seq != new_seq) { | |
1576 | struct ofport_dpif *ofport; | |
1577 | ||
1578 | HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) { | |
1579 | port_run(ofport); | |
1580 | } | |
1581 | ||
1582 | ofproto->change_seq = new_seq; | |
abe529af | 1583 | } |
e2d13c43 JS |
1584 | if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) { |
1585 | struct ofbundle *bundle; | |
1586 | ||
1587 | HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) { | |
1588 | bundle_run(bundle); | |
1589 | } | |
abe529af BP |
1590 | } |
1591 | ||
21f7563c | 1592 | stp_run(ofproto); |
9efd308e | 1593 | rstp_run(ofproto); |
509c0149 | 1594 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
30618594 EJ |
1595 | if (mac_learning_run(ofproto->ml)) { |
1596 | ofproto->backer->need_revalidate = REV_MAC_LEARNING; | |
1597 | } | |
509c0149 | 1598 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
abe529af | 1599 | |
6d95c4e8 FL |
1600 | if (mcast_snooping_run(ofproto->ms)) { |
1601 | ofproto->backer->need_revalidate = REV_MCAST_SNOOPING; | |
1602 | } | |
1603 | ||
e79a6c83 EJ |
1604 | new_dump_seq = seq_read(udpif_dump_seq(ofproto->backer->udpif)); |
1605 | if (ofproto->dump_seq != new_dump_seq) { | |
1606 | struct rule *rule, *next_rule; | |
f5857865 | 1607 | long long now = time_msec(); |
e79a6c83 EJ |
1608 | |
1609 | /* We know stats are relatively fresh, so now is a good time to do some | |
1610 | * periodic work. */ | |
1611 | ofproto->dump_seq = new_dump_seq; | |
1612 | ||
1613 | /* Expire OpenFlow flows whose idle_timeout or hard_timeout | |
1614 | * has passed. */ | |
1615 | ovs_mutex_lock(&ofproto_mutex); | |
1616 | LIST_FOR_EACH_SAFE (rule, next_rule, expirable, | |
1617 | &ofproto->up.expirable) { | |
f5857865 | 1618 | rule_expire(rule_dpif_cast(rule), now); |
e79a6c83 EJ |
1619 | } |
1620 | ovs_mutex_unlock(&ofproto_mutex); | |
1621 | ||
1622 | /* All outstanding data in existing flows has been accounted, so it's a | |
1623 | * good time to do bond rebalancing. */ | |
60cda7d6 | 1624 | if (ofproto->has_bonded_bundles) { |
e79a6c83 EJ |
1625 | struct ofbundle *bundle; |
1626 | ||
1627 | HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) { | |
60cda7d6 AZ |
1628 | if (bundle->bond) { |
1629 | bond_rebalance(bundle->bond); | |
e79a6c83 EJ |
1630 | } |
1631 | } | |
6814e51f BP |
1632 | } |
1633 | } | |
abe529af BP |
1634 | return 0; |
1635 | } | |
1636 | ||
1637 | static void | |
f07c97f5 | 1638 | ofproto_dpif_wait(struct ofproto *ofproto_) |
abe529af BP |
1639 | { |
1640 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
abe529af | 1641 | |
40358701 GS |
1642 | if (ofproto_get_flow_restore_wait()) { |
1643 | return; | |
1644 | } | |
1645 | ||
abe529af | 1646 | if (ofproto->sflow) { |
bae473fe | 1647 | dpif_sflow_wait(ofproto->sflow); |
abe529af | 1648 | } |
978427a5 RL |
1649 | if (ofproto->ipfix) { |
1650 | dpif_ipfix_wait(ofproto->ipfix); | |
1651 | } | |
e2d13c43 JS |
1652 | if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) { |
1653 | struct ofbundle *bundle; | |
1654 | ||
1655 | HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) { | |
1656 | bundle_wait(bundle); | |
1657 | } | |
abe529af | 1658 | } |
6fca1ffb BP |
1659 | if (ofproto->netflow) { |
1660 | netflow_wait(ofproto->netflow); | |
1661 | } | |
509c0149 | 1662 | ovs_rwlock_rdlock(&ofproto->ml->rwlock); |
1c313b88 | 1663 | mac_learning_wait(ofproto->ml); |
509c0149 | 1664 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
6d95c4e8 | 1665 | mcast_snooping_wait(ofproto->ms); |
21f7563c | 1666 | stp_wait(ofproto); |
2cc3c58e | 1667 | if (ofproto->backer->need_revalidate) { |
abe529af | 1668 | poll_immediate_wake(); |
abe529af | 1669 | } |
abe529af | 1670 | |
e79a6c83 | 1671 | seq_wait(udpif_dump_seq(ofproto->backer->udpif), ofproto->dump_seq); |
a2b53dec | 1672 | seq_wait(ofproto->ams_seq, ofproto->ams_seqno); |
0d085684 BP |
1673 | } |
1674 | ||
1c030aa5 EJ |
1675 | static void |
1676 | type_get_memory_usage(const char *type, struct simap *usage) | |
1677 | { | |
1678 | struct dpif_backer *backer; | |
1679 | ||
1680 | backer = shash_find_data(&all_dpif_backers, type); | |
1681 | if (backer) { | |
1682 | udpif_get_memory_usage(backer->udpif, usage); | |
1683 | } | |
1684 | } | |
1685 | ||
abe529af | 1686 | static void |
1b5b5071 | 1687 | flush(struct ofproto *ofproto_) |
abe529af | 1688 | { |
1b5b5071 AZ |
1689 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); |
1690 | struct dpif_backer *backer = ofproto->backer; | |
1691 | ||
1692 | if (backer) { | |
1693 | udpif_flush(backer->udpif); | |
1694 | } | |
abe529af BP |
1695 | } |
1696 | ||
6c1491fb | 1697 | static void |
3c1bb396 BP |
1698 | query_tables(struct ofproto *ofproto, |
1699 | struct ofputil_table_features *features, | |
1700 | struct ofputil_table_stats *stats) | |
6c1491fb | 1701 | { |
3c1bb396 | 1702 | strcpy(features->name, "classifier"); |
6c1491fb | 1703 | |
3c1bb396 BP |
1704 | if (stats) { |
1705 | int i; | |
6c1491fb | 1706 | |
3c1bb396 BP |
1707 | for (i = 0; i < ofproto->n_tables; i++) { |
1708 | unsigned long missed, matched; | |
d611866c | 1709 | |
afcea9ea JR |
1710 | atomic_read_relaxed(&ofproto->tables[i].n_matched, &matched); |
1711 | atomic_read_relaxed(&ofproto->tables[i].n_missed, &missed); | |
1712 | ||
3c1bb396 | 1713 | stats[i].matched_count = matched; |
3c1bb396 BP |
1714 | stats[i].lookup_count = matched + missed; |
1715 | } | |
d611866c | 1716 | } |
6c1491fb BP |
1717 | } |
1718 | ||
621b8064 | 1719 | static void |
44e0c35d | 1720 | set_tables_version(struct ofproto *ofproto_, ovs_version_t version) |
621b8064 JR |
1721 | { |
1722 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
1723 | ||
1724 | atomic_store_relaxed(&ofproto->tables_version, version); | |
1fc71871 | 1725 | ofproto->backer->need_revalidate = REV_FLOW_TABLE; |
621b8064 JR |
1726 | } |
1727 | ||
abe529af BP |
1728 | static struct ofport * |
1729 | port_alloc(void) | |
1730 | { | |
3da29e32 | 1731 | struct ofport_dpif *port = xzalloc(sizeof *port); |
abe529af BP |
1732 | return &port->up; |
1733 | } | |
1734 | ||
1735 | static void | |
1736 | port_dealloc(struct ofport *port_) | |
1737 | { | |
1738 | struct ofport_dpif *port = ofport_dpif_cast(port_); | |
1739 | free(port); | |
1740 | } | |
1741 | ||
1742 | static int | |
1743 | port_construct(struct ofport *port_) | |
1744 | { | |
1745 | struct ofport_dpif *port = ofport_dpif_cast(port_); | |
1746 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto); | |
b9ad7294 | 1747 | const struct netdev *netdev = port->up.netdev; |
3aa30359 | 1748 | char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; |
6d9e94b5 | 1749 | const char *dp_port_name; |
e1b1d06a JP |
1750 | struct dpif_port dpif_port; |
1751 | int error; | |
abe529af | 1752 | |
2cc3c58e | 1753 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
abe529af BP |
1754 | port->bundle = NULL; |
1755 | port->cfm = NULL; | |
ccc09689 | 1756 | port->bfd = NULL; |
0477baa9 | 1757 | port->lldp = NULL; |
f025bcb7 | 1758 | port->may_enable = false; |
21f7563c JP |
1759 | port->stp_port = NULL; |
1760 | port->stp_state = STP_DISABLED; | |
9efd308e DV |
1761 | port->rstp_port = NULL; |
1762 | port->rstp_state = RSTP_DISABLED; | |
42943cde | 1763 | port->is_tunnel = false; |
6cbbf4fa | 1764 | port->peer = NULL; |
55954f6e EJ |
1765 | port->qdscp = NULL; |
1766 | port->n_qdscp = 0; | |
b9ad7294 | 1767 | port->carrier_seq = netdev_get_carrier_resets(netdev); |
a6363cfd | 1768 | port->is_layer3 = netdev_vport_is_layer3(netdev); |
abe529af | 1769 | |
b9ad7294 | 1770 | if (netdev_vport_is_patch(netdev)) { |
743cea45 | 1771 | /* By bailing out here, we don't submit the port to the sFlow module |
185b4e3a MG |
1772 | * to be considered for counter polling export. This is correct |
1773 | * because the patch port represents an interface that sFlow considers | |
1774 | * to be "internal" to the switch as a whole, and therefore not a | |
1775 | * candidate for counter polling. */ | |
4e022ec0 | 1776 | port->odp_port = ODPP_NONE; |
6cbbf4fa | 1777 | ofport_update_peer(port); |
0a740f48 EJ |
1778 | return 0; |
1779 | } | |
1780 | ||
6d9e94b5 AZ |
1781 | dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf); |
1782 | error = dpif_port_query_by_name(ofproto->backer->dpif, dp_port_name, | |
e1b1d06a JP |
1783 | &dpif_port); |
1784 | if (error) { | |
1785 | return error; | |
1786 | } | |
1787 | ||
1788 | port->odp_port = dpif_port.port_no; | |
1789 | ||
b9ad7294 | 1790 | if (netdev_get_tunnel_config(netdev)) { |
a36de779 | 1791 | atomic_count_inc(&ofproto->backer->tnl_count); |
ea0797c9 | 1792 | error = tnl_port_add(port, port->up.netdev, port->odp_port, |
6d9e94b5 | 1793 | ovs_native_tunneling_is_on(ofproto), dp_port_name); |
ea0797c9 BP |
1794 | if (error) { |
1795 | atomic_count_dec(&ofproto->backer->tnl_count); | |
1796 | dpif_port_destroy(&dpif_port); | |
1797 | return error; | |
1798 | } | |
1799 | ||
42943cde | 1800 | port->is_tunnel = true; |
8b7ea2d4 WZ |
1801 | if (ofproto->ipfix) { |
1802 | dpif_ipfix_add_tunnel_port(ofproto->ipfix, port_, port->odp_port); | |
1803 | } | |
b9ad7294 EJ |
1804 | } else { |
1805 | /* Sanity-check that a mapping doesn't already exist. This | |
1806 | * shouldn't happen for non-tunnel ports. */ | |
1807 | if (odp_port_to_ofp_port(ofproto, port->odp_port) != OFPP_NONE) { | |
1808 | VLOG_ERR("port %s already has an OpenFlow port number", | |
1809 | dpif_port.name); | |
da78d43d | 1810 | dpif_port_destroy(&dpif_port); |
b9ad7294 EJ |
1811 | return EBUSY; |
1812 | } | |
e1b1d06a | 1813 | |
8449c4d6 | 1814 | ovs_rwlock_wrlock(&ofproto->backer->odp_to_ofport_lock); |
b9ad7294 | 1815 | hmap_insert(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node, |
f9c0c3ec | 1816 | hash_odp_port(port->odp_port)); |
8449c4d6 | 1817 | ovs_rwlock_unlock(&ofproto->backer->odp_to_ofport_lock); |
b9ad7294 | 1818 | } |
da78d43d | 1819 | dpif_port_destroy(&dpif_port); |
e1b1d06a | 1820 | |
abe529af | 1821 | if (ofproto->sflow) { |
e1b1d06a | 1822 | dpif_sflow_add_port(ofproto->sflow, port_, port->odp_port); |
abe529af BP |
1823 | } |
1824 | ||
1825 | return 0; | |
1826 | } | |
1827 | ||
1828 | static void | |
9aad5a5a | 1829 | port_destruct(struct ofport *port_, bool del) |
abe529af BP |
1830 | { |
1831 | struct ofport_dpif *port = ofport_dpif_cast(port_); | |
1832 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto); | |
02f8d646 | 1833 | const char *devname = netdev_get_name(port->up.netdev); |
3aa30359 BP |
1834 | char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; |
1835 | const char *dp_port_name; | |
abe529af | 1836 | |
7894e7da | 1837 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
84f0f298 | 1838 | xlate_txn_start(); |
46c88433 | 1839 | xlate_ofport_remove(port); |
84f0f298 | 1840 | xlate_txn_commit(); |
7894e7da | 1841 | |
3aa30359 BP |
1842 | dp_port_name = netdev_vport_get_dpif_port(port->up.netdev, namebuf, |
1843 | sizeof namebuf); | |
9aad5a5a | 1844 | if (del && dpif_port_exists(ofproto->backer->dpif, dp_port_name)) { |
acf60855 JP |
1845 | /* The underlying device is still there, so delete it. This |
1846 | * happens when the ofproto is being destroyed, since the caller | |
1847 | * assumes that removal of attached ports will happen as part of | |
1848 | * destruction. */ | |
42943cde | 1849 | if (!port->is_tunnel) { |
a614d823 KM |
1850 | dpif_port_del(ofproto->backer->dpif, port->odp_port); |
1851 | } | |
acf60855 JP |
1852 | } |
1853 | ||
6cbbf4fa EJ |
1854 | if (port->peer) { |
1855 | port->peer->peer = NULL; | |
1856 | port->peer = NULL; | |
1857 | } | |
1858 | ||
42943cde | 1859 | if (port->odp_port != ODPP_NONE && !port->is_tunnel) { |
8449c4d6 | 1860 | ovs_rwlock_wrlock(&ofproto->backer->odp_to_ofport_lock); |
0a740f48 | 1861 | hmap_remove(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node); |
8449c4d6 | 1862 | ovs_rwlock_unlock(&ofproto->backer->odp_to_ofport_lock); |
0a740f48 EJ |
1863 | } |
1864 | ||
a36de779 PS |
1865 | if (port->is_tunnel) { |
1866 | atomic_count_dec(&ofproto->backer->tnl_count); | |
1867 | } | |
1868 | ||
8b7ea2d4 WZ |
1869 | if (port->is_tunnel && ofproto->ipfix) { |
1870 | dpif_ipfix_del_tunnel_port(ofproto->ipfix, port->odp_port); | |
1871 | } | |
1872 | ||
42943cde | 1873 | tnl_port_del(port); |
02f8d646 | 1874 | sset_find_and_delete(&ofproto->ports, devname); |
0a740f48 | 1875 | sset_find_and_delete(&ofproto->ghost_ports, devname); |
abe529af | 1876 | bundle_remove(port_); |
a5610457 | 1877 | set_cfm(port_, NULL); |
8aee94b6 | 1878 | set_bfd(port_, NULL); |
0477baa9 | 1879 | set_lldp(port_, NULL); |
0c0c32d8 BP |
1880 | if (port->stp_port) { |
1881 | stp_port_disable(port->stp_port); | |
1882 | } | |
f025bcb7 | 1883 | set_rstp_port(port_, NULL); |
abe529af | 1884 | if (ofproto->sflow) { |
bae473fe | 1885 | dpif_sflow_del_port(ofproto->sflow, port->odp_port); |
abe529af | 1886 | } |
8b36f51e | 1887 | |
55954f6e | 1888 | free(port->qdscp); |
abe529af BP |
1889 | } |
1890 | ||
1891 | static void | |
1892 | port_modified(struct ofport *port_) | |
1893 | { | |
1894 | struct ofport_dpif *port = ofport_dpif_cast(port_); | |
a36de779 | 1895 | char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; |
6d9e94b5 | 1896 | const char *dp_port_name; |
a36de779 | 1897 | struct netdev *netdev = port->up.netdev; |
abe529af BP |
1898 | |
1899 | if (port->bundle && port->bundle->bond) { | |
a36de779 | 1900 | bond_slave_set_netdev(port->bundle->bond, port, netdev); |
abe529af | 1901 | } |
9d46b444 EJ |
1902 | |
1903 | if (port->cfm) { | |
a36de779 | 1904 | cfm_set_netdev(port->cfm, netdev); |
9d46b444 | 1905 | } |
f1e78bbd | 1906 | |
c1c4e8c7 | 1907 | if (port->bfd) { |
a36de779 | 1908 | bfd_set_netdev(port->bfd, netdev); |
c1c4e8c7 AW |
1909 | } |
1910 | ||
635c5db9 | 1911 | ofproto_dpif_monitor_port_update(port, port->bfd, port->cfm, |
74ff3298 | 1912 | port->lldp, &port->up.pp.hw_addr); |
635c5db9 | 1913 | |
6d9e94b5 | 1914 | dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf); |
a36de779 PS |
1915 | |
1916 | if (port->is_tunnel) { | |
1917 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto); | |
1918 | ||
1919 | if (tnl_port_reconfigure(port, netdev, port->odp_port, | |
6d9e94b5 AZ |
1920 | ovs_native_tunneling_is_on(ofproto), |
1921 | dp_port_name)) { | |
a36de779 PS |
1922 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
1923 | } | |
f1e78bbd | 1924 | } |
6cbbf4fa EJ |
1925 | |
1926 | ofport_update_peer(port); | |
abe529af BP |
1927 | } |
1928 | ||
1929 | static void | |
9e1fd49b | 1930 | port_reconfigured(struct ofport *port_, enum ofputil_port_config old_config) |
abe529af BP |
1931 | { |
1932 | struct ofport_dpif *port = ofport_dpif_cast(port_); | |
1933 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto); | |
9e1fd49b | 1934 | enum ofputil_port_config changed = old_config ^ port->up.pp.config; |
abe529af | 1935 | |
9e1fd49b | 1936 | if (changed & (OFPUTIL_PC_NO_RECV | OFPUTIL_PC_NO_RECV_STP | |
c57b2226 BP |
1937 | OFPUTIL_PC_NO_FWD | OFPUTIL_PC_NO_FLOOD | |
1938 | OFPUTIL_PC_NO_PACKET_IN)) { | |
2cc3c58e | 1939 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
7bde8dd8 | 1940 | |
9e1fd49b | 1941 | if (changed & OFPUTIL_PC_NO_FLOOD && port->bundle) { |
7bde8dd8 JP |
1942 | bundle_update(port->bundle); |
1943 | } | |
abe529af BP |
1944 | } |
1945 | } | |
1946 | ||
1947 | static int | |
1948 | set_sflow(struct ofproto *ofproto_, | |
1949 | const struct ofproto_sflow_options *sflow_options) | |
1950 | { | |
1951 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
bae473fe | 1952 | struct dpif_sflow *ds = ofproto->sflow; |
6ff686f2 | 1953 | |
abe529af | 1954 | if (sflow_options) { |
4fe0f203 | 1955 | uint32_t old_probability = ds ? dpif_sflow_get_probability(ds) : 0; |
bae473fe | 1956 | if (!ds) { |
abe529af BP |
1957 | struct ofport_dpif *ofport; |
1958 | ||
4213f19d | 1959 | ds = ofproto->sflow = dpif_sflow_create(); |
abe529af | 1960 | HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) { |
e1b1d06a | 1961 | dpif_sflow_add_port(ds, &ofport->up, ofport->odp_port); |
abe529af BP |
1962 | } |
1963 | } | |
bae473fe | 1964 | dpif_sflow_set_options(ds, sflow_options); |
4fe0f203 BP |
1965 | if (dpif_sflow_get_probability(ds) != old_probability) { |
1966 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
1967 | } | |
abe529af | 1968 | } else { |
6ff686f2 | 1969 | if (ds) { |
9723bcce | 1970 | dpif_sflow_unref(ds); |
2cc3c58e | 1971 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
6ff686f2 PS |
1972 | ofproto->sflow = NULL; |
1973 | } | |
abe529af BP |
1974 | } |
1975 | return 0; | |
1976 | } | |
1977 | ||
29089a54 RL |
1978 | static int |
1979 | set_ipfix( | |
1980 | struct ofproto *ofproto_, | |
1981 | const struct ofproto_ipfix_bridge_exporter_options *bridge_exporter_options, | |
1982 | const struct ofproto_ipfix_flow_exporter_options *flow_exporters_options, | |
1983 | size_t n_flow_exporters_options) | |
1984 | { | |
1985 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
1986 | struct dpif_ipfix *di = ofproto->ipfix; | |
978427a5 | 1987 | bool has_options = bridge_exporter_options || flow_exporters_options; |
8b7ea2d4 | 1988 | bool new_di = false; |
29089a54 | 1989 | |
978427a5 RL |
1990 | if (has_options && !di) { |
1991 | di = ofproto->ipfix = dpif_ipfix_create(); | |
8b7ea2d4 | 1992 | new_di = true; |
978427a5 RL |
1993 | } |
1994 | ||
1995 | if (di) { | |
1996 | /* Call set_options in any case to cleanly flush the flow | |
1997 | * caches in the last exporters that are to be destroyed. */ | |
29089a54 RL |
1998 | dpif_ipfix_set_options( |
1999 | di, bridge_exporter_options, flow_exporters_options, | |
2000 | n_flow_exporters_options); | |
978427a5 | 2001 | |
8b7ea2d4 WZ |
2002 | /* Add tunnel ports only when a new ipfix created */ |
2003 | if (new_di == true) { | |
2004 | struct ofport_dpif *ofport; | |
2005 | HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) { | |
2006 | if (ofport->is_tunnel == true) { | |
2007 | dpif_ipfix_add_tunnel_port(di, &ofport->up, ofport->odp_port); | |
2008 | } | |
2009 | } | |
2010 | } | |
2011 | ||
978427a5 | 2012 | if (!has_options) { |
d857c8aa | 2013 | dpif_ipfix_unref(di); |
29089a54 RL |
2014 | ofproto->ipfix = NULL; |
2015 | } | |
2016 | } | |
978427a5 | 2017 | |
29089a54 RL |
2018 | return 0; |
2019 | } | |
2020 | ||
fb8f22c1 BY |
2021 | static int |
2022 | get_ipfix_stats(const struct ofproto *ofproto_, | |
2023 | bool bridge_ipfix, | |
2024 | struct ovs_list *replies) | |
2025 | { | |
2026 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
2027 | struct dpif_ipfix *di = ofproto->ipfix; | |
2028 | ||
2029 | if (!di) { | |
2030 | return OFPERR_NXST_NOT_CONFIGURED; | |
2031 | } | |
2032 | ||
2033 | return dpif_ipfix_get_stats(di, bridge_ipfix, replies); | |
2034 | } | |
2035 | ||
abe529af | 2036 | static int |
a5610457 | 2037 | set_cfm(struct ofport *ofport_, const struct cfm_settings *s) |
abe529af BP |
2038 | { |
2039 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
4e5e44e3 AW |
2040 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); |
2041 | struct cfm *old = ofport->cfm; | |
635c5db9 | 2042 | int error = 0; |
abe529af | 2043 | |
635c5db9 | 2044 | if (s) { |
abe529af | 2045 | if (!ofport->cfm) { |
90967e95 | 2046 | ofport->cfm = cfm_create(ofport->up.netdev); |
abe529af BP |
2047 | } |
2048 | ||
a5610457 | 2049 | if (cfm_configure(ofport->cfm, s)) { |
635c5db9 AW |
2050 | error = 0; |
2051 | goto out; | |
abe529af BP |
2052 | } |
2053 | ||
2054 | error = EINVAL; | |
2055 | } | |
8e9a73fa | 2056 | cfm_unref(ofport->cfm); |
abe529af | 2057 | ofport->cfm = NULL; |
635c5db9 | 2058 | out: |
4e5e44e3 AW |
2059 | if (ofport->cfm != old) { |
2060 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
2061 | } | |
635c5db9 | 2062 | ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm, |
74ff3298 | 2063 | ofport->lldp, &ofport->up.pp.hw_addr); |
abe529af BP |
2064 | return error; |
2065 | } | |
2066 | ||
8f5514fe AW |
2067 | static bool |
2068 | cfm_status_changed(struct ofport *ofport_) | |
2069 | { | |
2070 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2071 | ||
2072 | return ofport->cfm ? cfm_check_status_change(ofport->cfm) : true; | |
2073 | } | |
2074 | ||
88bf179a | 2075 | static int |
9a9e3786 | 2076 | get_cfm_status(const struct ofport *ofport_, |
685acfd9 | 2077 | struct cfm_status *status) |
1de11730 EJ |
2078 | { |
2079 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
88bf179a | 2080 | int ret = 0; |
1de11730 EJ |
2081 | |
2082 | if (ofport->cfm) { | |
8f5514fe | 2083 | cfm_get_status(ofport->cfm, status); |
1de11730 | 2084 | } else { |
88bf179a | 2085 | ret = ENOENT; |
1de11730 | 2086 | } |
88bf179a AW |
2087 | |
2088 | return ret; | |
1de11730 | 2089 | } |
ccc09689 EJ |
2090 | |
2091 | static int | |
2092 | set_bfd(struct ofport *ofport_, const struct smap *cfg) | |
2093 | { | |
2094 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport_->ofproto); | |
2095 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2096 | struct bfd *old; | |
2097 | ||
2098 | old = ofport->bfd; | |
c1c4e8c7 AW |
2099 | ofport->bfd = bfd_configure(old, netdev_get_name(ofport->up.netdev), |
2100 | cfg, ofport->up.netdev); | |
ccc09689 EJ |
2101 | if (ofport->bfd != old) { |
2102 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
2103 | } | |
635c5db9 | 2104 | ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm, |
74ff3298 | 2105 | ofport->lldp, &ofport->up.pp.hw_addr); |
ccc09689 EJ |
2106 | return 0; |
2107 | } | |
2108 | ||
8f5514fe AW |
2109 | static bool |
2110 | bfd_status_changed(struct ofport *ofport_) | |
2111 | { | |
2112 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2113 | ||
2114 | return ofport->bfd ? bfd_check_status_change(ofport->bfd) : true; | |
2115 | } | |
2116 | ||
ccc09689 EJ |
2117 | static int |
2118 | get_bfd_status(struct ofport *ofport_, struct smap *smap) | |
2119 | { | |
2120 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
88bf179a | 2121 | int ret = 0; |
ccc09689 EJ |
2122 | |
2123 | if (ofport->bfd) { | |
8f5514fe | 2124 | bfd_get_status(ofport->bfd, smap); |
ccc09689 | 2125 | } else { |
88bf179a | 2126 | ret = ENOENT; |
ccc09689 | 2127 | } |
88bf179a AW |
2128 | |
2129 | return ret; | |
ccc09689 | 2130 | } |
0477baa9 DF |
2131 | |
2132 | static int | |
2133 | set_lldp(struct ofport *ofport_, | |
2134 | const struct smap *cfg) | |
2135 | { | |
2136 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2137 | int error = 0; | |
2138 | ||
2139 | if (cfg) { | |
2140 | if (!ofport->lldp) { | |
2141 | struct ofproto_dpif *ofproto; | |
2142 | ||
2143 | ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2144 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
2145 | ofport->lldp = lldp_create(ofport->up.netdev, ofport_->mtu, cfg); | |
2146 | } | |
2147 | ||
19aef6ef DF |
2148 | if (!lldp_configure(ofport->lldp, cfg)) { |
2149 | error = EINVAL; | |
0477baa9 | 2150 | } |
0477baa9 | 2151 | } |
19aef6ef DF |
2152 | if (error) { |
2153 | lldp_unref(ofport->lldp); | |
2154 | ofport->lldp = NULL; | |
2155 | } | |
2156 | ||
0477baa9 DF |
2157 | ofproto_dpif_monitor_port_update(ofport, |
2158 | ofport->bfd, | |
2159 | ofport->cfm, | |
2160 | ofport->lldp, | |
74ff3298 | 2161 | &ofport->up.pp.hw_addr); |
0477baa9 DF |
2162 | return error; |
2163 | } | |
2164 | ||
2165 | static bool | |
2166 | get_lldp_status(const struct ofport *ofport_, | |
2167 | struct lldp_status *status OVS_UNUSED) | |
2168 | { | |
2169 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2170 | ||
2171 | return ofport->lldp ? true : false; | |
2172 | } | |
2173 | ||
2174 | static int | |
2175 | set_aa(struct ofproto *ofproto OVS_UNUSED, | |
2176 | const struct aa_settings *s) | |
2177 | { | |
2178 | return aa_configure(s); | |
2179 | } | |
2180 | ||
2181 | static int | |
2182 | aa_mapping_set(struct ofproto *ofproto_ OVS_UNUSED, void *aux, | |
2183 | const struct aa_mapping_settings *s) | |
2184 | { | |
2185 | return aa_mapping_register(aux, s); | |
2186 | } | |
2187 | ||
2188 | static int | |
2189 | aa_mapping_unset(struct ofproto *ofproto OVS_UNUSED, void *aux) | |
2190 | { | |
2191 | return aa_mapping_unregister(aux); | |
2192 | } | |
2193 | ||
2194 | static int | |
2195 | aa_vlan_get_queued(struct ofproto *ofproto OVS_UNUSED, struct ovs_list *list) | |
2196 | { | |
2197 | return aa_get_vlan_queued(list); | |
2198 | } | |
2199 | ||
2200 | static unsigned int | |
2201 | aa_vlan_get_queue_size(struct ofproto *ofproto OVS_UNUSED) | |
2202 | { | |
2203 | return aa_get_vlan_queue_size(); | |
2204 | } | |
2205 | ||
abe529af | 2206 | \f |
21f7563c JP |
2207 | /* Spanning Tree. */ |
2208 | ||
6b90bc57 | 2209 | /* Called while rstp_mutex is held. */ |
9efd308e | 2210 | static void |
cf62fa4c | 2211 | rstp_send_bpdu_cb(struct dp_packet *pkt, void *ofport_, void *ofproto_) |
9efd308e DV |
2212 | { |
2213 | struct ofproto_dpif *ofproto = ofproto_; | |
6b90bc57 | 2214 | struct ofport_dpif *ofport = ofport_; |
cf62fa4c | 2215 | struct eth_header *eth = dp_packet_l2(pkt); |
6b90bc57 | 2216 | |
74ff3298 | 2217 | netdev_get_etheraddr(ofport->up.netdev, ð->eth_src); |
6b90bc57 JR |
2218 | if (eth_addr_is_zero(eth->eth_src)) { |
2219 | VLOG_WARN_RL(&rl, "%s port %d: cannot send RSTP BPDU on a port which " | |
2220 | "does not have a configured source MAC address.", | |
2221 | ofproto->up.name, ofp_to_u16(ofport->up.ofp_port)); | |
9efd308e | 2222 | } else { |
2eb79142 | 2223 | ofproto_dpif_send_packet(ofport, false, pkt); |
9efd308e | 2224 | } |
cf62fa4c | 2225 | dp_packet_delete(pkt); |
9efd308e DV |
2226 | } |
2227 | ||
21f7563c | 2228 | static void |
cf62fa4c | 2229 | send_bpdu_cb(struct dp_packet *pkt, int port_num, void *ofproto_) |
21f7563c JP |
2230 | { |
2231 | struct ofproto_dpif *ofproto = ofproto_; | |
2232 | struct stp_port *sp = stp_get_port(ofproto->stp, port_num); | |
2233 | struct ofport_dpif *ofport; | |
2234 | ||
2235 | ofport = stp_port_get_aux(sp); | |
2236 | if (!ofport) { | |
2237 | VLOG_WARN_RL(&rl, "%s: cannot send BPDU on unknown port %d", | |
2238 | ofproto->up.name, port_num); | |
2239 | } else { | |
cf62fa4c | 2240 | struct eth_header *eth = dp_packet_l2(pkt); |
21f7563c | 2241 | |
74ff3298 | 2242 | netdev_get_etheraddr(ofport->up.netdev, ð->eth_src); |
21f7563c JP |
2243 | if (eth_addr_is_zero(eth->eth_src)) { |
2244 | VLOG_WARN_RL(&rl, "%s: cannot send BPDU on port %d " | |
2245 | "with unknown MAC", ofproto->up.name, port_num); | |
2246 | } else { | |
2eb79142 | 2247 | ofproto_dpif_send_packet(ofport, false, pkt); |
21f7563c JP |
2248 | } |
2249 | } | |
cf62fa4c | 2250 | dp_packet_delete(pkt); |
21f7563c JP |
2251 | } |
2252 | ||
9efd308e DV |
2253 | /* Configure RSTP on 'ofproto_' using the settings defined in 's'. */ |
2254 | static void | |
2255 | set_rstp(struct ofproto *ofproto_, const struct ofproto_rstp_settings *s) | |
2256 | { | |
2257 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
2258 | ||
2259 | /* Only revalidate flows if the configuration changed. */ | |
2260 | if (!s != !ofproto->rstp) { | |
2261 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
2262 | } | |
2263 | ||
2264 | if (s) { | |
2265 | if (!ofproto->rstp) { | |
2266 | ofproto->rstp = rstp_create(ofproto_->name, s->address, | |
4b30ba05 | 2267 | rstp_send_bpdu_cb, ofproto); |
9efd308e DV |
2268 | ofproto->rstp_last_tick = time_msec(); |
2269 | } | |
2270 | rstp_set_bridge_address(ofproto->rstp, s->address); | |
2271 | rstp_set_bridge_priority(ofproto->rstp, s->priority); | |
2272 | rstp_set_bridge_ageing_time(ofproto->rstp, s->ageing_time); | |
2273 | rstp_set_bridge_force_protocol_version(ofproto->rstp, | |
2274 | s->force_protocol_version); | |
2275 | rstp_set_bridge_max_age(ofproto->rstp, s->bridge_max_age); | |
2276 | rstp_set_bridge_forward_delay(ofproto->rstp, s->bridge_forward_delay); | |
2277 | rstp_set_bridge_transmit_hold_count(ofproto->rstp, | |
2278 | s->transmit_hold_count); | |
2279 | } else { | |
2280 | struct ofport *ofport; | |
2281 | HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) { | |
2282 | set_rstp_port(ofport, NULL); | |
2283 | } | |
2284 | rstp_unref(ofproto->rstp); | |
2285 | ofproto->rstp = NULL; | |
2286 | } | |
2287 | } | |
2288 | ||
2289 | static void | |
2290 | get_rstp_status(struct ofproto *ofproto_, struct ofproto_rstp_status *s) | |
2291 | { | |
2292 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
2293 | ||
2294 | if (ofproto->rstp) { | |
2295 | s->enabled = true; | |
2296 | s->root_id = rstp_get_root_id(ofproto->rstp); | |
2297 | s->bridge_id = rstp_get_bridge_id(ofproto->rstp); | |
2298 | s->designated_id = rstp_get_designated_id(ofproto->rstp); | |
2299 | s->root_path_cost = rstp_get_root_path_cost(ofproto->rstp); | |
2300 | s->designated_port_id = rstp_get_designated_port_id(ofproto->rstp); | |
2301 | s->bridge_port_id = rstp_get_bridge_port_id(ofproto->rstp); | |
2302 | } else { | |
2303 | s->enabled = false; | |
2304 | } | |
2305 | } | |
2306 | ||
2307 | static void | |
2308 | update_rstp_port_state(struct ofport_dpif *ofport) | |
2309 | { | |
2310 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2311 | enum rstp_state state; | |
2312 | ||
2313 | /* Figure out new state. */ | |
2314 | state = ofport->rstp_port ? rstp_port_get_state(ofport->rstp_port) | |
2315 | : RSTP_DISABLED; | |
2316 | ||
2317 | /* Update state. */ | |
2318 | if (ofport->rstp_state != state) { | |
2319 | enum ofputil_port_state of_state; | |
2320 | bool fwd_change; | |
2321 | ||
9a0bb428 JR |
2322 | VLOG_DBG("port %s: RSTP state changed from %s to %s", |
2323 | netdev_get_name(ofport->up.netdev), | |
2324 | rstp_state_name(ofport->rstp_state), | |
2325 | rstp_state_name(state)); | |
2372c146 | 2326 | |
9efd308e | 2327 | if (rstp_learn_in_state(ofport->rstp_state) |
66ff280d JR |
2328 | != rstp_learn_in_state(state)) { |
2329 | /* XXX: Learning action flows should also be flushed. */ | |
2330 | if (ofport->bundle) { | |
2372c146 JR |
2331 | if (!rstp_shift_root_learned_address(ofproto->rstp) |
2332 | || rstp_get_old_root_aux(ofproto->rstp) != ofport) { | |
2333 | bundle_flush_macs(ofport->bundle, false); | |
2334 | } | |
66ff280d | 2335 | } |
9efd308e DV |
2336 | } |
2337 | fwd_change = rstp_forward_in_state(ofport->rstp_state) | |
2338 | != rstp_forward_in_state(state); | |
2339 | ||
2340 | ofproto->backer->need_revalidate = REV_RSTP; | |
2341 | ofport->rstp_state = state; | |
2342 | ||
2343 | if (fwd_change && ofport->bundle) { | |
2344 | bundle_update(ofport->bundle); | |
2345 | } | |
2346 | ||
2347 | /* Update the RSTP state bits in the OpenFlow port description. */ | |
2348 | of_state = ofport->up.pp.state & ~OFPUTIL_PS_STP_MASK; | |
2349 | of_state |= (state == RSTP_LEARNING ? OFPUTIL_PS_STP_LEARN | |
2350 | : state == RSTP_FORWARDING ? OFPUTIL_PS_STP_FORWARD | |
2351 | : state == RSTP_DISCARDING ? OFPUTIL_PS_STP_LISTEN | |
2352 | : 0); | |
2353 | ofproto_port_set_state(&ofport->up, of_state); | |
2354 | } | |
2355 | } | |
2356 | ||
2357 | static void | |
2358 | rstp_run(struct ofproto_dpif *ofproto) | |
2359 | { | |
2360 | if (ofproto->rstp) { | |
2361 | long long int now = time_msec(); | |
2362 | long long int elapsed = now - ofproto->rstp_last_tick; | |
2363 | struct rstp_port *rp; | |
f025bcb7 | 2364 | struct ofport_dpif *ofport; |
54d3863b | 2365 | |
9efd308e DV |
2366 | /* Every second, decrease the values of the timers. */ |
2367 | if (elapsed >= 1000) { | |
2368 | rstp_tick_timers(ofproto->rstp); | |
2369 | ofproto->rstp_last_tick = now; | |
2370 | } | |
f025bcb7 JR |
2371 | rp = NULL; |
2372 | while ((ofport = rstp_get_next_changed_port_aux(ofproto->rstp, &rp))) { | |
2373 | update_rstp_port_state(ofport); | |
9efd308e | 2374 | } |
66ff280d JR |
2375 | rp = NULL; |
2376 | ofport = NULL; | |
9efd308e DV |
2377 | /* FIXME: This check should be done on-event (i.e., when setting |
2378 | * p->fdb_flush) and not periodically. | |
2379 | */ | |
66ff280d | 2380 | while ((ofport = rstp_check_and_reset_fdb_flush(ofproto->rstp, &rp))) { |
2372c146 JR |
2381 | if (!rstp_shift_root_learned_address(ofproto->rstp) |
2382 | || rstp_get_old_root_aux(ofproto->rstp) != ofport) { | |
2383 | bundle_flush_macs(ofport->bundle, false); | |
2384 | } | |
2385 | } | |
2386 | ||
2387 | if (rstp_shift_root_learned_address(ofproto->rstp)) { | |
c7e4f0b2 DV |
2388 | struct ofport_dpif *old_root_aux = |
2389 | (struct ofport_dpif *)rstp_get_old_root_aux(ofproto->rstp); | |
2390 | struct ofport_dpif *new_root_aux = | |
2391 | (struct ofport_dpif *)rstp_get_new_root_aux(ofproto->rstp); | |
2392 | if (old_root_aux != NULL && new_root_aux != NULL) { | |
2393 | bundle_move(old_root_aux->bundle, new_root_aux->bundle); | |
2394 | rstp_reset_root_changed(ofproto->rstp); | |
2395 | } | |
9efd308e DV |
2396 | } |
2397 | } | |
2398 | } | |
2399 | ||
21f7563c JP |
2400 | /* Configures STP on 'ofproto_' using the settings defined in 's'. */ |
2401 | static int | |
2402 | set_stp(struct ofproto *ofproto_, const struct ofproto_stp_settings *s) | |
2403 | { | |
2404 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
2405 | ||
2406 | /* Only revalidate flows if the configuration changed. */ | |
2407 | if (!s != !ofproto->stp) { | |
2cc3c58e | 2408 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
21f7563c JP |
2409 | } |
2410 | ||
2411 | if (s) { | |
2412 | if (!ofproto->stp) { | |
2413 | ofproto->stp = stp_create(ofproto_->name, s->system_id, | |
2414 | send_bpdu_cb, ofproto); | |
2415 | ofproto->stp_last_tick = time_msec(); | |
2416 | } | |
2417 | ||
2418 | stp_set_bridge_id(ofproto->stp, s->system_id); | |
2419 | stp_set_bridge_priority(ofproto->stp, s->priority); | |
2420 | stp_set_hello_time(ofproto->stp, s->hello_time); | |
2421 | stp_set_max_age(ofproto->stp, s->max_age); | |
2422 | stp_set_forward_delay(ofproto->stp, s->fwd_delay); | |
2423 | } else { | |
851bf71d EJ |
2424 | struct ofport *ofport; |
2425 | ||
2426 | HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) { | |
2427 | set_stp_port(ofport, NULL); | |
2428 | } | |
2429 | ||
bd54dbcd | 2430 | stp_unref(ofproto->stp); |
21f7563c JP |
2431 | ofproto->stp = NULL; |
2432 | } | |
2433 | ||
2434 | return 0; | |
2435 | } | |
2436 | ||
2437 | static int | |
2438 | get_stp_status(struct ofproto *ofproto_, struct ofproto_stp_status *s) | |
2439 | { | |
2440 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
2441 | ||
2442 | if (ofproto->stp) { | |
2443 | s->enabled = true; | |
2444 | s->bridge_id = stp_get_bridge_id(ofproto->stp); | |
2445 | s->designated_root = stp_get_designated_root(ofproto->stp); | |
2446 | s->root_path_cost = stp_get_root_path_cost(ofproto->stp); | |
2447 | } else { | |
2448 | s->enabled = false; | |
2449 | } | |
2450 | ||
2451 | return 0; | |
2452 | } | |
2453 | ||
2454 | static void | |
2455 | update_stp_port_state(struct ofport_dpif *ofport) | |
2456 | { | |
2457 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2458 | enum stp_state state; | |
2459 | ||
2460 | /* Figure out new state. */ | |
2461 | state = ofport->stp_port ? stp_port_get_state(ofport->stp_port) | |
2462 | : STP_DISABLED; | |
2463 | ||
2464 | /* Update state. */ | |
2465 | if (ofport->stp_state != state) { | |
9e1fd49b | 2466 | enum ofputil_port_state of_state; |
21f7563c JP |
2467 | bool fwd_change; |
2468 | ||
9a0bb428 JR |
2469 | VLOG_DBG("port %s: STP state changed from %s to %s", |
2470 | netdev_get_name(ofport->up.netdev), | |
2471 | stp_state_name(ofport->stp_state), | |
2472 | stp_state_name(state)); | |
21f7563c JP |
2473 | if (stp_learn_in_state(ofport->stp_state) |
2474 | != stp_learn_in_state(state)) { | |
2475 | /* xxx Learning action flows should also be flushed. */ | |
509c0149 | 2476 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
30618594 | 2477 | mac_learning_flush(ofproto->ml); |
509c0149 | 2478 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
6d95c4e8 | 2479 | mcast_snooping_mdb_flush(ofproto->ms); |
21f7563c JP |
2480 | } |
2481 | fwd_change = stp_forward_in_state(ofport->stp_state) | |
2482 | != stp_forward_in_state(state); | |
2483 | ||
2cc3c58e | 2484 | ofproto->backer->need_revalidate = REV_STP; |
21f7563c JP |
2485 | ofport->stp_state = state; |
2486 | ofport->stp_state_entered = time_msec(); | |
2487 | ||
b308140a | 2488 | if (fwd_change && ofport->bundle) { |
21f7563c JP |
2489 | bundle_update(ofport->bundle); |
2490 | } | |
2491 | ||
2492 | /* Update the STP state bits in the OpenFlow port description. */ | |
9e1fd49b BP |
2493 | of_state = ofport->up.pp.state & ~OFPUTIL_PS_STP_MASK; |
2494 | of_state |= (state == STP_LISTENING ? OFPUTIL_PS_STP_LISTEN | |
2495 | : state == STP_LEARNING ? OFPUTIL_PS_STP_LEARN | |
2496 | : state == STP_FORWARDING ? OFPUTIL_PS_STP_FORWARD | |
2497 | : state == STP_BLOCKING ? OFPUTIL_PS_STP_BLOCK | |
2498 | : 0); | |
21f7563c JP |
2499 | ofproto_port_set_state(&ofport->up, of_state); |
2500 | } | |
2501 | } | |
2502 | ||
2503 | /* Configures STP on 'ofport_' using the settings defined in 's'. The | |
2504 | * caller is responsible for assigning STP port numbers and ensuring | |
2505 | * there are no duplicates. */ | |
2506 | static int | |
2507 | set_stp_port(struct ofport *ofport_, | |
2508 | const struct ofproto_port_stp_settings *s) | |
2509 | { | |
2510 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2511 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2512 | struct stp_port *sp = ofport->stp_port; | |
2513 | ||
2514 | if (!s || !s->enable) { | |
2515 | if (sp) { | |
2516 | ofport->stp_port = NULL; | |
2517 | stp_port_disable(sp); | |
ecd12731 | 2518 | update_stp_port_state(ofport); |
21f7563c JP |
2519 | } |
2520 | return 0; | |
2521 | } else if (sp && stp_port_no(sp) != s->port_num | |
f025bcb7 | 2522 | && ofport == stp_port_get_aux(sp)) { |
21f7563c JP |
2523 | /* The port-id changed, so disable the old one if it's not |
2524 | * already in use by another port. */ | |
2525 | stp_port_disable(sp); | |
2526 | } | |
2527 | ||
2528 | sp = ofport->stp_port = stp_get_port(ofproto->stp, s->port_num); | |
21f7563c | 2529 | |
fb20b0bf JR |
2530 | /* Set name before enabling the port so that debugging messages can print |
2531 | * the name. */ | |
11306274 | 2532 | stp_port_set_name(sp, netdev_get_name(ofport->up.netdev)); |
fb20b0bf JR |
2533 | stp_port_enable(sp); |
2534 | ||
21f7563c JP |
2535 | stp_port_set_aux(sp, ofport); |
2536 | stp_port_set_priority(sp, s->priority); | |
2537 | stp_port_set_path_cost(sp, s->path_cost); | |
2538 | ||
2539 | update_stp_port_state(ofport); | |
2540 | ||
2541 | return 0; | |
2542 | } | |
2543 | ||
2544 | static int | |
2545 | get_stp_port_status(struct ofport *ofport_, | |
2546 | struct ofproto_port_stp_status *s) | |
2547 | { | |
2548 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2549 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2550 | struct stp_port *sp = ofport->stp_port; | |
2551 | ||
2552 | if (!ofproto->stp || !sp) { | |
2553 | s->enabled = false; | |
2554 | return 0; | |
2555 | } | |
2556 | ||
2557 | s->enabled = true; | |
2558 | s->port_id = stp_port_get_id(sp); | |
2559 | s->state = stp_port_get_state(sp); | |
2560 | s->sec_in_state = (time_msec() - ofport->stp_state_entered) / 1000; | |
2561 | s->role = stp_port_get_role(sp); | |
fd28ce3a JS |
2562 | |
2563 | return 0; | |
2564 | } | |
2565 | ||
2566 | static int | |
2567 | get_stp_port_stats(struct ofport *ofport_, | |
2568 | struct ofproto_port_stp_stats *s) | |
2569 | { | |
2570 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2571 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2572 | struct stp_port *sp = ofport->stp_port; | |
2573 | ||
2574 | if (!ofproto->stp || !sp) { | |
2575 | s->enabled = false; | |
2576 | return 0; | |
2577 | } | |
2578 | ||
2579 | s->enabled = true; | |
80740385 | 2580 | stp_port_get_counts(sp, &s->tx_count, &s->rx_count, &s->error_count); |
21f7563c JP |
2581 | |
2582 | return 0; | |
2583 | } | |
2584 | ||
2585 | static void | |
2586 | stp_run(struct ofproto_dpif *ofproto) | |
2587 | { | |
2588 | if (ofproto->stp) { | |
2589 | long long int now = time_msec(); | |
2590 | long long int elapsed = now - ofproto->stp_last_tick; | |
2591 | struct stp_port *sp; | |
2592 | ||
2593 | if (elapsed > 0) { | |
2594 | stp_tick(ofproto->stp, MIN(INT_MAX, elapsed)); | |
2595 | ofproto->stp_last_tick = now; | |
2596 | } | |
2597 | while (stp_get_changed_port(ofproto->stp, &sp)) { | |
2598 | struct ofport_dpif *ofport = stp_port_get_aux(sp); | |
2599 | ||
2600 | if (ofport) { | |
2601 | update_stp_port_state(ofport); | |
2602 | } | |
2603 | } | |
6ae50723 EJ |
2604 | |
2605 | if (stp_check_and_reset_fdb_flush(ofproto->stp)) { | |
509c0149 | 2606 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
30618594 | 2607 | mac_learning_flush(ofproto->ml); |
509c0149 | 2608 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
6d95c4e8 | 2609 | mcast_snooping_mdb_flush(ofproto->ms); |
6ae50723 | 2610 | } |
21f7563c JP |
2611 | } |
2612 | } | |
2613 | ||
2614 | static void | |
2615 | stp_wait(struct ofproto_dpif *ofproto) | |
2616 | { | |
2617 | if (ofproto->stp) { | |
2618 | poll_timer_wait(1000); | |
2619 | } | |
2620 | } | |
9efd308e DV |
2621 | |
2622 | /* Configures RSTP on 'ofport_' using the settings defined in 's'. The | |
2623 | * caller is responsible for assigning RSTP port numbers and ensuring | |
2624 | * there are no duplicates. */ | |
2625 | static void | |
2626 | set_rstp_port(struct ofport *ofport_, | |
cc33c223 | 2627 | const struct ofproto_port_rstp_settings *s) |
9efd308e DV |
2628 | { |
2629 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2630 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2631 | struct rstp_port *rp = ofport->rstp_port; | |
9efd308e DV |
2632 | |
2633 | if (!s || !s->enable) { | |
2634 | if (rp) { | |
e73e9165 JR |
2635 | rstp_port_set_aux(rp, NULL); |
2636 | rstp_port_set_state(rp, RSTP_DISABLED); | |
2637 | rstp_port_set_mac_operational(rp, false); | |
9efd308e | 2638 | ofport->rstp_port = NULL; |
e73e9165 | 2639 | rstp_port_unref(rp); |
9efd308e DV |
2640 | update_rstp_port_state(ofport); |
2641 | } | |
9efd308e DV |
2642 | return; |
2643 | } | |
f025bcb7 JR |
2644 | |
2645 | /* Check if need to add a new port. */ | |
9efd308e DV |
2646 | if (!rp) { |
2647 | rp = ofport->rstp_port = rstp_add_port(ofproto->rstp); | |
2648 | } | |
9efd308e | 2649 | |
f025bcb7 | 2650 | rstp_port_set(rp, s->port_num, s->priority, s->path_cost, |
67e8c1ac JR |
2651 | s->admin_edge_port, s->auto_edge, |
2652 | s->admin_p2p_mac_state, s->admin_port_state, s->mcheck, | |
2653 | ofport); | |
9efd308e | 2654 | update_rstp_port_state(ofport); |
29db47ce JR |
2655 | /* Synchronize operational status. */ |
2656 | rstp_port_set_mac_operational(rp, ofport->may_enable); | |
9efd308e DV |
2657 | } |
2658 | ||
2659 | static void | |
2660 | get_rstp_port_status(struct ofport *ofport_, | |
2661 | struct ofproto_port_rstp_status *s) | |
2662 | { | |
2663 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2664 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
2665 | struct rstp_port *rp = ofport->rstp_port; | |
2666 | ||
2667 | if (!ofproto->rstp || !rp) { | |
2668 | s->enabled = false; | |
2669 | return; | |
2670 | } | |
2671 | ||
2672 | s->enabled = true; | |
9c64e6b8 JR |
2673 | rstp_port_get_status(rp, &s->port_id, &s->state, &s->role, |
2674 | &s->designated_bridge_id, &s->designated_port_id, | |
2675 | &s->designated_path_cost, &s->tx_count, | |
f025bcb7 | 2676 | &s->rx_count, &s->error_count, &s->uptime); |
9efd308e DV |
2677 | } |
2678 | ||
21f7563c | 2679 | \f |
8b36f51e | 2680 | static int |
55954f6e | 2681 | set_queues(struct ofport *ofport_, const struct ofproto_port_queue *qdscp, |
8b36f51e EJ |
2682 | size_t n_qdscp) |
2683 | { | |
2684 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
2685 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
8b36f51e | 2686 | |
55954f6e EJ |
2687 | if (ofport->n_qdscp != n_qdscp |
2688 | || (n_qdscp && memcmp(ofport->qdscp, qdscp, | |
2689 | n_qdscp * sizeof *qdscp))) { | |
2cc3c58e | 2690 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
55954f6e EJ |
2691 | free(ofport->qdscp); |
2692 | ofport->qdscp = n_qdscp | |
2693 | ? xmemdup(qdscp, n_qdscp * sizeof *qdscp) | |
2694 | : NULL; | |
2695 | ofport->n_qdscp = n_qdscp; | |
8b36f51e EJ |
2696 | } |
2697 | ||
8b36f51e EJ |
2698 | return 0; |
2699 | } | |
2700 | \f | |
abe529af BP |
2701 | /* Bundles. */ |
2702 | ||
b44a10b7 BP |
2703 | /* Expires all MAC learning entries associated with 'bundle' and forces its |
2704 | * ofproto to revalidate every flow. | |
2705 | * | |
2706 | * Normally MAC learning entries are removed only from the ofproto associated | |
2707 | * with 'bundle', but if 'all_ofprotos' is true, then the MAC learning entries | |
2708 | * are removed from every ofproto. When patch ports and SLB bonds are in use | |
2709 | * and a VM migration happens and the gratuitous ARPs are somehow lost, this | |
2710 | * avoids a MAC_ENTRY_IDLE_TIME delay before the migrated VM can communicate | |
2711 | * with the host from which it migrated. */ | |
abe529af | 2712 | static void |
b44a10b7 | 2713 | bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos) |
abe529af BP |
2714 | { |
2715 | struct ofproto_dpif *ofproto = bundle->ofproto; | |
2716 | struct mac_learning *ml = ofproto->ml; | |
2717 | struct mac_entry *mac, *next_mac; | |
2718 | ||
2cc3c58e | 2719 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
509c0149 | 2720 | ovs_rwlock_wrlock(&ml->rwlock); |
abe529af | 2721 | LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) { |
9d078ec2 | 2722 | if (mac_entry_get_port(ml, mac) == bundle) { |
b44a10b7 BP |
2723 | if (all_ofprotos) { |
2724 | struct ofproto_dpif *o; | |
2725 | ||
2726 | HMAP_FOR_EACH (o, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
2727 | if (o != ofproto) { | |
2728 | struct mac_entry *e; | |
2729 | ||
509c0149 | 2730 | ovs_rwlock_wrlock(&o->ml->rwlock); |
30618594 | 2731 | e = mac_learning_lookup(o->ml, mac->mac, mac->vlan); |
b44a10b7 | 2732 | if (e) { |
b44a10b7 BP |
2733 | mac_learning_expire(o->ml, e); |
2734 | } | |
509c0149 | 2735 | ovs_rwlock_unlock(&o->ml->rwlock); |
b44a10b7 BP |
2736 | } |
2737 | } | |
2738 | } | |
2739 | ||
abe529af BP |
2740 | mac_learning_expire(ml, mac); |
2741 | } | |
2742 | } | |
509c0149 | 2743 | ovs_rwlock_unlock(&ml->rwlock); |
abe529af BP |
2744 | } |
2745 | ||
2372c146 JR |
2746 | static void |
2747 | bundle_move(struct ofbundle *old, struct ofbundle *new) | |
2748 | { | |
2749 | struct ofproto_dpif *ofproto = old->ofproto; | |
2750 | struct mac_learning *ml = ofproto->ml; | |
2751 | struct mac_entry *mac, *next_mac; | |
2752 | ||
2753 | ovs_assert(new->ofproto == old->ofproto); | |
2754 | ||
2755 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
2756 | ovs_rwlock_wrlock(&ml->rwlock); | |
2757 | LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) { | |
9d078ec2 BP |
2758 | if (mac_entry_get_port(ml, mac) == old) { |
2759 | mac_entry_set_port(ml, mac, new); | |
2372c146 JR |
2760 | } |
2761 | } | |
2762 | ovs_rwlock_unlock(&ml->rwlock); | |
2763 | } | |
2764 | ||
abe529af BP |
2765 | static struct ofbundle * |
2766 | bundle_lookup(const struct ofproto_dpif *ofproto, void *aux) | |
2767 | { | |
2768 | struct ofbundle *bundle; | |
2769 | ||
2770 | HMAP_FOR_EACH_IN_BUCKET (bundle, hmap_node, hash_pointer(aux, 0), | |
2771 | &ofproto->bundles) { | |
2772 | if (bundle->aux == aux) { | |
2773 | return bundle; | |
2774 | } | |
2775 | } | |
2776 | return NULL; | |
2777 | } | |
2778 | ||
7bde8dd8 JP |
2779 | static void |
2780 | bundle_update(struct ofbundle *bundle) | |
2781 | { | |
2782 | struct ofport_dpif *port; | |
2783 | ||
2784 | bundle->floodable = true; | |
2785 | LIST_FOR_EACH (port, bundle_node, &bundle->ports) { | |
9e1fd49b | 2786 | if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD |
a6363cfd | 2787 | || port->is_layer3 |
4b5f1996 DV |
2788 | || (bundle->ofproto->stp && !stp_forward_in_state(port->stp_state)) |
2789 | || (bundle->ofproto->rstp && !rstp_forward_in_state(port->rstp_state))) { | |
7bde8dd8 JP |
2790 | bundle->floodable = false; |
2791 | break; | |
2792 | } | |
2793 | } | |
2794 | } | |
2795 | ||
abe529af BP |
2796 | static void |
2797 | bundle_del_port(struct ofport_dpif *port) | |
2798 | { | |
2799 | struct ofbundle *bundle = port->bundle; | |
2800 | ||
2cc3c58e | 2801 | bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE; |
6f77f4ae | 2802 | |
417e7e66 | 2803 | ovs_list_remove(&port->bundle_node); |
abe529af BP |
2804 | port->bundle = NULL; |
2805 | ||
2806 | if (bundle->lacp) { | |
2807 | lacp_slave_unregister(bundle->lacp, port); | |
2808 | } | |
2809 | if (bundle->bond) { | |
2810 | bond_slave_unregister(bundle->bond, port); | |
2811 | } | |
2812 | ||
7bde8dd8 | 2813 | bundle_update(bundle); |
abe529af BP |
2814 | } |
2815 | ||
2816 | static bool | |
4e022ec0 | 2817 | bundle_add_port(struct ofbundle *bundle, ofp_port_t ofp_port, |
df53d41c | 2818 | struct lacp_slave_settings *lacp) |
abe529af BP |
2819 | { |
2820 | struct ofport_dpif *port; | |
2821 | ||
e672ff9b | 2822 | port = ofp_port_to_ofport(bundle->ofproto, ofp_port); |
abe529af BP |
2823 | if (!port) { |
2824 | return false; | |
2825 | } | |
2826 | ||
2827 | if (port->bundle != bundle) { | |
2cc3c58e | 2828 | bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE; |
abe529af | 2829 | if (port->bundle) { |
e019a574 | 2830 | bundle_remove(&port->up); |
abe529af BP |
2831 | } |
2832 | ||
2833 | port->bundle = bundle; | |
417e7e66 | 2834 | ovs_list_push_back(&bundle->ports, &port->bundle_node); |
9e1fd49b | 2835 | if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD |
a6363cfd | 2836 | || port->is_layer3 |
4b5f1996 DV |
2837 | || (bundle->ofproto->stp && !stp_forward_in_state(port->stp_state)) |
2838 | || (bundle->ofproto->rstp && !rstp_forward_in_state(port->rstp_state))) { | |
abe529af BP |
2839 | bundle->floodable = false; |
2840 | } | |
2841 | } | |
2842 | if (lacp) { | |
2cc3c58e | 2843 | bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE; |
abe529af BP |
2844 | lacp_slave_register(bundle->lacp, port, lacp); |
2845 | } | |
2846 | ||
2847 | return true; | |
2848 | } | |
2849 | ||
2850 | static void | |
2851 | bundle_destroy(struct ofbundle *bundle) | |
2852 | { | |
2853 | struct ofproto_dpif *ofproto; | |
2854 | struct ofport_dpif *port, *next_port; | |
abe529af BP |
2855 | |
2856 | if (!bundle) { | |
2857 | return; | |
2858 | } | |
2859 | ||
2860 | ofproto = bundle->ofproto; | |
67912650 | 2861 | mbridge_unregister_bundle(ofproto->mbridge, bundle); |
abe529af | 2862 | |
84f0f298 | 2863 | xlate_txn_start(); |
46c88433 | 2864 | xlate_bundle_remove(bundle); |
84f0f298 | 2865 | xlate_txn_commit(); |
46c88433 | 2866 | |
abe529af BP |
2867 | LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) { |
2868 | bundle_del_port(port); | |
2869 | } | |
2870 | ||
b44a10b7 | 2871 | bundle_flush_macs(bundle, true); |
abe529af BP |
2872 | hmap_remove(&ofproto->bundles, &bundle->hmap_node); |
2873 | free(bundle->name); | |
2874 | free(bundle->trunks); | |
91779071 | 2875 | lacp_unref(bundle->lacp); |
03366a2d | 2876 | bond_unref(bundle->bond); |
abe529af BP |
2877 | free(bundle); |
2878 | } | |
2879 | ||
2880 | static int | |
2881 | bundle_set(struct ofproto *ofproto_, void *aux, | |
2882 | const struct ofproto_bundle_settings *s) | |
2883 | { | |
2884 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
2885 | bool need_flush = false; | |
abe529af BP |
2886 | struct ofport_dpif *port; |
2887 | struct ofbundle *bundle; | |
ecac4ebf BP |
2888 | unsigned long *trunks; |
2889 | int vlan; | |
abe529af BP |
2890 | size_t i; |
2891 | bool ok; | |
2892 | ||
2893 | if (!s) { | |
2894 | bundle_destroy(bundle_lookup(ofproto, aux)); | |
2895 | return 0; | |
2896 | } | |
2897 | ||
cb22974d BP |
2898 | ovs_assert(s->n_slaves == 1 || s->bond != NULL); |
2899 | ovs_assert((s->lacp != NULL) == (s->lacp_slaves != NULL)); | |
abe529af BP |
2900 | |
2901 | bundle = bundle_lookup(ofproto, aux); | |
2902 | if (!bundle) { | |
2903 | bundle = xmalloc(sizeof *bundle); | |
2904 | ||
2905 | bundle->ofproto = ofproto; | |
2906 | hmap_insert(&ofproto->bundles, &bundle->hmap_node, | |
2907 | hash_pointer(aux, 0)); | |
2908 | bundle->aux = aux; | |
2909 | bundle->name = NULL; | |
2910 | ||
417e7e66 | 2911 | ovs_list_init(&bundle->ports); |
ecac4ebf | 2912 | bundle->vlan_mode = PORT_VLAN_TRUNK; |
abe529af BP |
2913 | bundle->vlan = -1; |
2914 | bundle->trunks = NULL; | |
5e9ceccd | 2915 | bundle->use_priority_tags = s->use_priority_tags; |
abe529af BP |
2916 | bundle->lacp = NULL; |
2917 | bundle->bond = NULL; | |
2918 | ||
2919 | bundle->floodable = true; | |
ec7ceaed | 2920 | mbridge_register_bundle(ofproto->mbridge, bundle); |
abe529af BP |
2921 | } |
2922 | ||
2923 | if (!bundle->name || strcmp(s->name, bundle->name)) { | |
2924 | free(bundle->name); | |
2925 | bundle->name = xstrdup(s->name); | |
2926 | } | |
2927 | ||
2928 | /* LACP. */ | |
2929 | if (s->lacp) { | |
e2d13c43 | 2930 | ofproto->lacp_enabled = true; |
abe529af | 2931 | if (!bundle->lacp) { |
2cc3c58e | 2932 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
abe529af BP |
2933 | bundle->lacp = lacp_create(); |
2934 | } | |
2935 | lacp_configure(bundle->lacp, s->lacp); | |
2936 | } else { | |
91779071 | 2937 | lacp_unref(bundle->lacp); |
abe529af BP |
2938 | bundle->lacp = NULL; |
2939 | } | |
2940 | ||
2941 | /* Update set of ports. */ | |
2942 | ok = true; | |
2943 | for (i = 0; i < s->n_slaves; i++) { | |
2944 | if (!bundle_add_port(bundle, s->slaves[i], | |
df53d41c | 2945 | s->lacp ? &s->lacp_slaves[i] : NULL)) { |
abe529af BP |
2946 | ok = false; |
2947 | } | |
2948 | } | |
417e7e66 | 2949 | if (!ok || ovs_list_size(&bundle->ports) != s->n_slaves) { |
abe529af BP |
2950 | struct ofport_dpif *next_port; |
2951 | ||
2952 | LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) { | |
2953 | for (i = 0; i < s->n_slaves; i++) { | |
56c769ab | 2954 | if (s->slaves[i] == port->up.ofp_port) { |
abe529af BP |
2955 | goto found; |
2956 | } | |
2957 | } | |
2958 | ||
2959 | bundle_del_port(port); | |
2960 | found: ; | |
2961 | } | |
2962 | } | |
417e7e66 | 2963 | ovs_assert(ovs_list_size(&bundle->ports) <= s->n_slaves); |
abe529af | 2964 | |
417e7e66 | 2965 | if (ovs_list_is_empty(&bundle->ports)) { |
abe529af BP |
2966 | bundle_destroy(bundle); |
2967 | return EINVAL; | |
2968 | } | |
2969 | ||
ecac4ebf | 2970 | /* Set VLAN tagging mode */ |
5e9ceccd BP |
2971 | if (s->vlan_mode != bundle->vlan_mode |
2972 | || s->use_priority_tags != bundle->use_priority_tags) { | |
ecac4ebf | 2973 | bundle->vlan_mode = s->vlan_mode; |
5e9ceccd | 2974 | bundle->use_priority_tags = s->use_priority_tags; |
ecac4ebf BP |
2975 | need_flush = true; |
2976 | } | |
2977 | ||
abe529af | 2978 | /* Set VLAN tag. */ |
ecac4ebf BP |
2979 | vlan = (s->vlan_mode == PORT_VLAN_TRUNK ? -1 |
2980 | : s->vlan >= 0 && s->vlan <= 4095 ? s->vlan | |
2981 | : 0); | |
2982 | if (vlan != bundle->vlan) { | |
2983 | bundle->vlan = vlan; | |
abe529af BP |
2984 | need_flush = true; |
2985 | } | |
2986 | ||
2987 | /* Get trunked VLANs. */ | |
ecac4ebf BP |
2988 | switch (s->vlan_mode) { |
2989 | case PORT_VLAN_ACCESS: | |
2990 | trunks = NULL; | |
2991 | break; | |
2992 | ||
2993 | case PORT_VLAN_TRUNK: | |
ebc56baa | 2994 | trunks = CONST_CAST(unsigned long *, s->trunks); |
ecac4ebf BP |
2995 | break; |
2996 | ||
2997 | case PORT_VLAN_NATIVE_UNTAGGED: | |
2998 | case PORT_VLAN_NATIVE_TAGGED: | |
2999 | if (vlan != 0 && (!s->trunks | |
3000 | || !bitmap_is_set(s->trunks, vlan) | |
3001 | || bitmap_is_set(s->trunks, 0))) { | |
3002 | /* Force trunking the native VLAN and prohibit trunking VLAN 0. */ | |
3003 | if (s->trunks) { | |
3004 | trunks = bitmap_clone(s->trunks, 4096); | |
3005 | } else { | |
3006 | trunks = bitmap_allocate1(4096); | |
3007 | } | |
3008 | bitmap_set1(trunks, vlan); | |
3009 | bitmap_set0(trunks, 0); | |
3010 | } else { | |
ebc56baa | 3011 | trunks = CONST_CAST(unsigned long *, s->trunks); |
ecac4ebf BP |
3012 | } |
3013 | break; | |
3014 | ||
3015 | default: | |
428b2edd | 3016 | OVS_NOT_REACHED(); |
ecac4ebf | 3017 | } |
abe529af BP |
3018 | if (!vlan_bitmap_equal(trunks, bundle->trunks)) { |
3019 | free(bundle->trunks); | |
ecac4ebf BP |
3020 | if (trunks == s->trunks) { |
3021 | bundle->trunks = vlan_bitmap_clone(trunks); | |
3022 | } else { | |
3023 | bundle->trunks = trunks; | |
3024 | trunks = NULL; | |
3025 | } | |
abe529af BP |
3026 | need_flush = true; |
3027 | } | |
ecac4ebf BP |
3028 | if (trunks != s->trunks) { |
3029 | free(trunks); | |
3030 | } | |
abe529af BP |
3031 | |
3032 | /* Bonding. */ | |
417e7e66 | 3033 | if (!ovs_list_is_short(&bundle->ports)) { |
abe529af BP |
3034 | bundle->ofproto->has_bonded_bundles = true; |
3035 | if (bundle->bond) { | |
3036 | if (bond_reconfigure(bundle->bond, s->bond)) { | |
2cc3c58e | 3037 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
abe529af BP |
3038 | } |
3039 | } else { | |
adcf00ba | 3040 | bundle->bond = bond_create(s->bond, ofproto); |
2cc3c58e | 3041 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
abe529af BP |
3042 | } |
3043 | ||
3044 | LIST_FOR_EACH (port, bundle_node, &bundle->ports) { | |
adcf00ba AZ |
3045 | bond_slave_register(bundle->bond, port, |
3046 | port->up.ofp_port, port->up.netdev); | |
abe529af BP |
3047 | } |
3048 | } else { | |
03366a2d | 3049 | bond_unref(bundle->bond); |
abe529af BP |
3050 | bundle->bond = NULL; |
3051 | } | |
3052 | ||
3053 | /* If we changed something that would affect MAC learning, un-learn | |
3054 | * everything on this port and force flow revalidation. */ | |
3055 | if (need_flush) { | |
b44a10b7 | 3056 | bundle_flush_macs(bundle, false); |
abe529af BP |
3057 | } |
3058 | ||
3059 | return 0; | |
3060 | } | |
3061 | ||
3062 | static void | |
3063 | bundle_remove(struct ofport *port_) | |
3064 | { | |
3065 | struct ofport_dpif *port = ofport_dpif_cast(port_); | |
3066 | struct ofbundle *bundle = port->bundle; | |
3067 | ||
3068 | if (bundle) { | |
3069 | bundle_del_port(port); | |
417e7e66 | 3070 | if (ovs_list_is_empty(&bundle->ports)) { |
abe529af | 3071 | bundle_destroy(bundle); |
417e7e66 | 3072 | } else if (ovs_list_is_short(&bundle->ports)) { |
03366a2d | 3073 | bond_unref(bundle->bond); |
abe529af BP |
3074 | bundle->bond = NULL; |
3075 | } | |
3076 | } | |
3077 | } | |
3078 | ||
3079 | static void | |
5f877369 | 3080 | send_pdu_cb(void *port_, const void *pdu, size_t pdu_size) |
abe529af BP |
3081 | { |
3082 | static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10); | |
3083 | struct ofport_dpif *port = port_; | |
74ff3298 | 3084 | struct eth_addr ea; |
abe529af BP |
3085 | int error; |
3086 | ||
74ff3298 | 3087 | error = netdev_get_etheraddr(port->up.netdev, &ea); |
abe529af | 3088 | if (!error) { |
cf62fa4c | 3089 | struct dp_packet packet; |
5f877369 | 3090 | void *packet_pdu; |
abe529af | 3091 | |
cf62fa4c | 3092 | dp_packet_init(&packet, 0); |
abe529af | 3093 | packet_pdu = eth_compose(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP, |
5f877369 EJ |
3094 | pdu_size); |
3095 | memcpy(packet_pdu, pdu, pdu_size); | |
3096 | ||
2eb79142 | 3097 | ofproto_dpif_send_packet(port, false, &packet); |
cf62fa4c | 3098 | dp_packet_uninit(&packet); |
abe529af BP |
3099 | } else { |
3100 | VLOG_ERR_RL(&rl, "port %s: cannot obtain Ethernet address of iface " | |
3101 | "%s (%s)", port->bundle->name, | |
10a89ef0 | 3102 | netdev_get_name(port->up.netdev), ovs_strerror(error)); |
abe529af BP |
3103 | } |
3104 | } | |
3105 | ||
3106 | static void | |
3107 | bundle_send_learning_packets(struct ofbundle *bundle) | |
3108 | { | |
3109 | struct ofproto_dpif *ofproto = bundle->ofproto; | |
3110 | int error, n_packets, n_errors; | |
3111 | struct mac_entry *e; | |
8613db65 DDP |
3112 | struct pkt_list { |
3113 | struct ovs_list list_node; | |
3114 | struct ofport_dpif *port; | |
3115 | struct dp_packet *pkt; | |
3116 | } *pkt_node; | |
ca6ba700 | 3117 | struct ovs_list packets; |
abe529af | 3118 | |
417e7e66 | 3119 | ovs_list_init(&packets); |
509c0149 | 3120 | ovs_rwlock_rdlock(&ofproto->ml->rwlock); |
abe529af | 3121 | LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) { |
9d078ec2 | 3122 | if (mac_entry_get_port(ofproto->ml, e) != bundle) { |
8613db65 DDP |
3123 | pkt_node = xmalloc(sizeof *pkt_node); |
3124 | pkt_node->pkt = bond_compose_learning_packet(bundle->bond, | |
3125 | e->mac, e->vlan, | |
3126 | (void **)&pkt_node->port); | |
417e7e66 | 3127 | ovs_list_push_back(&packets, &pkt_node->list_node); |
abe529af BP |
3128 | } |
3129 | } | |
509c0149 | 3130 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
abe529af | 3131 | |
0165217e | 3132 | error = n_packets = n_errors = 0; |
8613db65 | 3133 | LIST_FOR_EACH_POP (pkt_node, list_node, &packets) { |
0165217e EJ |
3134 | int ret; |
3135 | ||
2eb79142 | 3136 | ret = ofproto_dpif_send_packet(pkt_node->port, false, pkt_node->pkt); |
8613db65 DDP |
3137 | dp_packet_delete(pkt_node->pkt); |
3138 | free(pkt_node); | |
0165217e EJ |
3139 | if (ret) { |
3140 | error = ret; | |
3141 | n_errors++; | |
3142 | } | |
3143 | n_packets++; | |
3144 | } | |
0165217e | 3145 | |
abe529af BP |
3146 | if (n_errors) { |
3147 | static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); | |
3148 | VLOG_WARN_RL(&rl, "bond %s: %d errors sending %d gratuitous learning " | |
3149 | "packets, last error was: %s", | |
10a89ef0 | 3150 | bundle->name, n_errors, n_packets, ovs_strerror(error)); |
abe529af BP |
3151 | } else { |
3152 | VLOG_DBG("bond %s: sent %d gratuitous learning packets", | |
3153 | bundle->name, n_packets); | |
3154 | } | |
3155 | } | |
3156 | ||
3157 | static void | |
3158 | bundle_run(struct ofbundle *bundle) | |
3159 | { | |
3160 | if (bundle->lacp) { | |
3161 | lacp_run(bundle->lacp, send_pdu_cb); | |
3162 | } | |
3163 | if (bundle->bond) { | |
3164 | struct ofport_dpif *port; | |
3165 | ||
3166 | LIST_FOR_EACH (port, bundle_node, &bundle->ports) { | |
015e08bc | 3167 | bond_slave_set_may_enable(bundle->bond, port, port->may_enable); |
abe529af BP |
3168 | } |
3169 | ||
4a1b8f30 EJ |
3170 | if (bond_run(bundle->bond, lacp_status(bundle->lacp))) { |
3171 | bundle->ofproto->backer->need_revalidate = REV_BOND; | |
3172 | } | |
3173 | ||
abe529af BP |
3174 | if (bond_should_send_learning_packets(bundle->bond)) { |
3175 | bundle_send_learning_packets(bundle); | |
3176 | } | |
3177 | } | |
3178 | } | |
3179 | ||
3180 | static void | |
3181 | bundle_wait(struct ofbundle *bundle) | |
3182 | { | |
3183 | if (bundle->lacp) { | |
3184 | lacp_wait(bundle->lacp); | |
3185 | } | |
3186 | if (bundle->bond) { | |
3187 | bond_wait(bundle->bond); | |
3188 | } | |
3189 | } | |
3190 | \f | |
3191 | /* Mirrors. */ | |
3192 | ||
3193 | static int | |
ec7ceaed EJ |
3194 | mirror_set__(struct ofproto *ofproto_, void *aux, |
3195 | const struct ofproto_mirror_settings *s) | |
abe529af BP |
3196 | { |
3197 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
ec7ceaed EJ |
3198 | struct ofbundle **srcs, **dsts; |
3199 | int error; | |
3200 | size_t i; | |
abe529af | 3201 | |
abe529af | 3202 | if (!s) { |
ec7ceaed | 3203 | mirror_destroy(ofproto->mbridge, aux); |
abe529af BP |
3204 | return 0; |
3205 | } | |
3206 | ||
ec7ceaed EJ |
3207 | srcs = xmalloc(s->n_srcs * sizeof *srcs); |
3208 | dsts = xmalloc(s->n_dsts * sizeof *dsts); | |
abe529af | 3209 | |
ec7ceaed EJ |
3210 | for (i = 0; i < s->n_srcs; i++) { |
3211 | srcs[i] = bundle_lookup(ofproto, s->srcs[i]); | |
abe529af BP |
3212 | } |
3213 | ||
ec7ceaed EJ |
3214 | for (i = 0; i < s->n_dsts; i++) { |
3215 | dsts[i] = bundle_lookup(ofproto, s->dsts[i]); | |
abe529af BP |
3216 | } |
3217 | ||
ec7ceaed EJ |
3218 | error = mirror_set(ofproto->mbridge, aux, s->name, srcs, s->n_srcs, dsts, |
3219 | s->n_dsts, s->src_vlans, | |
1356dbd1 WT |
3220 | bundle_lookup(ofproto, s->out_bundle), |
3221 | s->snaplen, s->out_vlan); | |
ec7ceaed EJ |
3222 | free(srcs); |
3223 | free(dsts); | |
3224 | return error; | |
abe529af BP |
3225 | } |
3226 | ||
9d24de3b | 3227 | static int |
ec7ceaed EJ |
3228 | mirror_get_stats__(struct ofproto *ofproto, void *aux, |
3229 | uint64_t *packets, uint64_t *bytes) | |
9d24de3b | 3230 | { |
ec7ceaed EJ |
3231 | return mirror_get_stats(ofproto_dpif_cast(ofproto)->mbridge, aux, packets, |
3232 | bytes); | |
9d24de3b JP |
3233 | } |
3234 | ||
abe529af BP |
3235 | static int |
3236 | set_flood_vlans(struct ofproto *ofproto_, unsigned long *flood_vlans) | |
3237 | { | |
3238 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
509c0149 | 3239 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
abe529af | 3240 | if (mac_learning_set_flood_vlans(ofproto->ml, flood_vlans)) { |
30618594 | 3241 | mac_learning_flush(ofproto->ml); |
abe529af | 3242 | } |
509c0149 | 3243 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
abe529af BP |
3244 | return 0; |
3245 | } | |
3246 | ||
3247 | static bool | |
b4affc74 | 3248 | is_mirror_output_bundle(const struct ofproto *ofproto_, void *aux) |
abe529af BP |
3249 | { |
3250 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
3251 | struct ofbundle *bundle = bundle_lookup(ofproto, aux); | |
ec7ceaed | 3252 | return bundle && mirror_bundle_out(ofproto->mbridge, bundle) != 0; |
abe529af | 3253 | } |
8402c74b SS |
3254 | |
3255 | static void | |
b53055f4 | 3256 | forward_bpdu_changed(struct ofproto *ofproto_) |
8402c74b SS |
3257 | { |
3258 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
2cc3c58e | 3259 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
8402c74b | 3260 | } |
e764773c BP |
3261 | |
3262 | static void | |
c4069512 BP |
3263 | set_mac_table_config(struct ofproto *ofproto_, unsigned int idle_time, |
3264 | size_t max_entries) | |
e764773c BP |
3265 | { |
3266 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
509c0149 | 3267 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
e764773c | 3268 | mac_learning_set_idle_time(ofproto->ml, idle_time); |
c4069512 | 3269 | mac_learning_set_max_entries(ofproto->ml, max_entries); |
509c0149 | 3270 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
e764773c | 3271 | } |
7c38d0a5 FL |
3272 | |
3273 | /* Configures multicast snooping on 'ofport' using the settings | |
3274 | * defined in 's'. */ | |
3275 | static int | |
3276 | set_mcast_snooping(struct ofproto *ofproto_, | |
3277 | const struct ofproto_mcast_snooping_settings *s) | |
3278 | { | |
3279 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
3280 | ||
3281 | /* Only revalidate flows if the configuration changed. */ | |
3282 | if (!s != !ofproto->ms) { | |
3283 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
3284 | } | |
3285 | ||
3286 | if (s) { | |
3287 | if (!ofproto->ms) { | |
3288 | ofproto->ms = mcast_snooping_create(); | |
3289 | } | |
3290 | ||
3291 | ovs_rwlock_wrlock(&ofproto->ms->rwlock); | |
3292 | mcast_snooping_set_idle_time(ofproto->ms, s->idle_time); | |
3293 | mcast_snooping_set_max_entries(ofproto->ms, s->max_entries); | |
3294 | if (mcast_snooping_set_flood_unreg(ofproto->ms, s->flood_unreg)) { | |
3295 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
3296 | } | |
3297 | ovs_rwlock_unlock(&ofproto->ms->rwlock); | |
3298 | } else { | |
3299 | mcast_snooping_unref(ofproto->ms); | |
3300 | ofproto->ms = NULL; | |
3301 | } | |
3302 | ||
3303 | return 0; | |
3304 | } | |
3305 | ||
8e04a33f | 3306 | /* Configures multicast snooping port's flood settings on 'ofproto'. */ |
7c38d0a5 | 3307 | static int |
8e04a33f FL |
3308 | set_mcast_snooping_port(struct ofproto *ofproto_, void *aux, |
3309 | const struct ofproto_mcast_snooping_port_settings *s) | |
7c38d0a5 FL |
3310 | { |
3311 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
3312 | struct ofbundle *bundle = bundle_lookup(ofproto, aux); | |
3313 | ||
8e04a33f | 3314 | if (ofproto->ms && s) { |
7c38d0a5 | 3315 | ovs_rwlock_wrlock(&ofproto->ms->rwlock); |
8e04a33f FL |
3316 | mcast_snooping_set_port_flood(ofproto->ms, bundle, s->flood); |
3317 | mcast_snooping_set_port_flood_reports(ofproto->ms, bundle, | |
3318 | s->flood_reports); | |
7c38d0a5 FL |
3319 | ovs_rwlock_unlock(&ofproto->ms->rwlock); |
3320 | } | |
3321 | return 0; | |
3322 | } | |
3323 | ||
abe529af BP |
3324 | \f |
3325 | /* Ports. */ | |
3326 | ||
e672ff9b JR |
3327 | struct ofport_dpif * |
3328 | ofp_port_to_ofport(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port) | |
abe529af | 3329 | { |
7df6a8bd BP |
3330 | struct ofport *ofport = ofproto_get_port(&ofproto->up, ofp_port); |
3331 | return ofport ? ofport_dpif_cast(ofport) : NULL; | |
abe529af BP |
3332 | } |
3333 | ||
abe529af | 3334 | static void |
e1b1d06a JP |
3335 | ofproto_port_from_dpif_port(struct ofproto_dpif *ofproto, |
3336 | struct ofproto_port *ofproto_port, | |
abe529af BP |
3337 | struct dpif_port *dpif_port) |
3338 | { | |
3339 | ofproto_port->name = dpif_port->name; | |
3340 | ofproto_port->type = dpif_port->type; | |
e1b1d06a | 3341 | ofproto_port->ofp_port = odp_port_to_ofp_port(ofproto, dpif_port->port_no); |
abe529af BP |
3342 | } |
3343 | ||
6cbbf4fa EJ |
3344 | static void |
3345 | ofport_update_peer(struct ofport_dpif *ofport) | |
0a740f48 EJ |
3346 | { |
3347 | const struct ofproto_dpif *ofproto; | |
6cbbf4fa | 3348 | struct dpif_backer *backer; |
161b6042 | 3349 | char *peer_name; |
6cbbf4fa EJ |
3350 | |
3351 | if (!netdev_vport_is_patch(ofport->up.netdev)) { | |
3352 | return; | |
3353 | } | |
3354 | ||
3355 | backer = ofproto_dpif_cast(ofport->up.ofproto)->backer; | |
7894e7da | 3356 | backer->need_revalidate = REV_RECONFIGURE; |
0a740f48 | 3357 | |
6cbbf4fa EJ |
3358 | if (ofport->peer) { |
3359 | ofport->peer->peer = NULL; | |
3360 | ofport->peer = NULL; | |
3361 | } | |
3362 | ||
3363 | peer_name = netdev_vport_patch_peer(ofport->up.netdev); | |
3364 | if (!peer_name) { | |
3365 | return; | |
0a740f48 EJ |
3366 | } |
3367 | ||
3368 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
6cbbf4fa EJ |
3369 | struct ofport *peer_ofport; |
3370 | struct ofport_dpif *peer; | |
161b6042 | 3371 | char *peer_peer; |
0a740f48 | 3372 | |
462abef2 EJ |
3373 | if (ofproto->backer != backer) { |
3374 | continue; | |
3375 | } | |
3376 | ||
6cbbf4fa EJ |
3377 | peer_ofport = shash_find_data(&ofproto->up.port_by_name, peer_name); |
3378 | if (!peer_ofport) { | |
3379 | continue; | |
3380 | } | |
3381 | ||
3382 | peer = ofport_dpif_cast(peer_ofport); | |
3383 | peer_peer = netdev_vport_patch_peer(peer->up.netdev); | |
3384 | if (peer_peer && !strcmp(netdev_get_name(ofport->up.netdev), | |
3385 | peer_peer)) { | |
3386 | ofport->peer = peer; | |
3387 | ofport->peer->peer = ofport; | |
0a740f48 | 3388 | } |
161b6042 | 3389 | free(peer_peer); |
6cbbf4fa | 3390 | |
161b6042 | 3391 | break; |
0a740f48 | 3392 | } |
161b6042 | 3393 | free(peer_name); |
0a740f48 EJ |
3394 | } |
3395 | ||
abe529af BP |
3396 | static void |
3397 | port_run(struct ofport_dpif *ofport) | |
3398 | { | |
3e5b3fdb EJ |
3399 | long long int carrier_seq = netdev_get_carrier_resets(ofport->up.netdev); |
3400 | bool carrier_changed = carrier_seq != ofport->carrier_seq; | |
015e08bc | 3401 | bool enable = netdev_get_carrier(ofport->up.netdev); |
2d344ba5 AW |
3402 | bool cfm_enable = false; |
3403 | bool bfd_enable = false; | |
015e08bc | 3404 | |
3e5b3fdb EJ |
3405 | ofport->carrier_seq = carrier_seq; |
3406 | ||
abe529af | 3407 | if (ofport->cfm) { |
4653c558 EJ |
3408 | int cfm_opup = cfm_get_opup(ofport->cfm); |
3409 | ||
2d344ba5 | 3410 | cfm_enable = !cfm_get_fault(ofport->cfm); |
4653c558 EJ |
3411 | |
3412 | if (cfm_opup >= 0) { | |
2d344ba5 | 3413 | cfm_enable = cfm_enable && cfm_opup; |
4653c558 | 3414 | } |
abe529af | 3415 | } |
015e08bc | 3416 | |
ccc09689 | 3417 | if (ofport->bfd) { |
2d344ba5 AW |
3418 | bfd_enable = bfd_forwarding(ofport->bfd); |
3419 | } | |
3420 | ||
3421 | if (ofport->bfd || ofport->cfm) { | |
3422 | enable = enable && (cfm_enable || bfd_enable); | |
ccc09689 EJ |
3423 | } |
3424 | ||
015e08bc EJ |
3425 | if (ofport->bundle) { |
3426 | enable = enable && lacp_slave_may_enable(ofport->bundle->lacp, ofport); | |
3e5b3fdb EJ |
3427 | if (carrier_changed) { |
3428 | lacp_slave_carrier_changed(ofport->bundle->lacp, ofport); | |
3429 | } | |
015e08bc EJ |
3430 | } |
3431 | ||
daff3353 EJ |
3432 | if (ofport->may_enable != enable) { |
3433 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
daff3353 | 3434 | |
f025bcb7 | 3435 | ofproto->backer->need_revalidate = REV_PORT_TOGGLED; |
9efd308e | 3436 | |
f025bcb7 | 3437 | if (ofport->rstp_port) { |
9efd308e DV |
3438 | rstp_port_set_mac_operational(ofport->rstp_port, enable); |
3439 | } | |
3440 | } | |
f025bcb7 JR |
3441 | |
3442 | ofport->may_enable = enable; | |
abe529af BP |
3443 | } |
3444 | ||
abe529af BP |
3445 | static int |
3446 | port_query_by_name(const struct ofproto *ofproto_, const char *devname, | |
3447 | struct ofproto_port *ofproto_port) | |
3448 | { | |
3449 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
3450 | struct dpif_port dpif_port; | |
3451 | int error; | |
3452 | ||
0a740f48 EJ |
3453 | if (sset_contains(&ofproto->ghost_ports, devname)) { |
3454 | const char *type = netdev_get_type_from_name(devname); | |
3455 | ||
3456 | /* We may be called before ofproto->up.port_by_name is populated with | |
3457 | * the appropriate ofport. For this reason, we must get the name and | |
3458 | * type from the netdev layer directly. */ | |
3459 | if (type) { | |
3460 | const struct ofport *ofport; | |
3461 | ||
3462 | ofport = shash_find_data(&ofproto->up.port_by_name, devname); | |
3463 | ofproto_port->ofp_port = ofport ? ofport->ofp_port : OFPP_NONE; | |
3464 | ofproto_port->name = xstrdup(devname); | |
3465 | ofproto_port->type = xstrdup(type); | |
3466 | return 0; | |
3467 | } | |
3468 | return ENODEV; | |
3469 | } | |
3470 | ||
acf60855 JP |
3471 | if (!sset_contains(&ofproto->ports, devname)) { |
3472 | return ENODEV; | |
3473 | } | |
3474 | error = dpif_port_query_by_name(ofproto->backer->dpif, | |
3475 | devname, &dpif_port); | |
abe529af | 3476 | if (!error) { |
e1b1d06a | 3477 | ofproto_port_from_dpif_port(ofproto, ofproto_port, &dpif_port); |
abe529af BP |
3478 | } |
3479 | return error; | |
3480 | } | |
3481 | ||
3482 | static int | |
e1b1d06a | 3483 | port_add(struct ofproto *ofproto_, struct netdev *netdev) |
abe529af BP |
3484 | { |
3485 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
b9ad7294 | 3486 | const char *devname = netdev_get_name(netdev); |
3aa30359 BP |
3487 | char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; |
3488 | const char *dp_port_name; | |
abe529af | 3489 | |
0a740f48 EJ |
3490 | if (netdev_vport_is_patch(netdev)) { |
3491 | sset_add(&ofproto->ghost_ports, netdev_get_name(netdev)); | |
3492 | return 0; | |
3493 | } | |
3494 | ||
3aa30359 | 3495 | dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf); |
b9ad7294 | 3496 | if (!dpif_port_exists(ofproto->backer->dpif, dp_port_name)) { |
4e022ec0 | 3497 | odp_port_t port_no = ODPP_NONE; |
7d82ab2e KM |
3498 | int error; |
3499 | ||
3500 | error = dpif_port_add(ofproto->backer->dpif, netdev, &port_no); | |
b9ad7294 EJ |
3501 | if (error) { |
3502 | return error; | |
3503 | } | |
7d82ab2e | 3504 | if (netdev_get_tunnel_config(netdev)) { |
4e022ec0 AW |
3505 | simap_put(&ofproto->backer->tnl_backers, |
3506 | dp_port_name, odp_to_u32(port_no)); | |
7d82ab2e | 3507 | } |
acf60855 | 3508 | } |
b9ad7294 EJ |
3509 | |
3510 | if (netdev_get_tunnel_config(netdev)) { | |
3511 | sset_add(&ofproto->ghost_ports, devname); | |
b9ad7294 EJ |
3512 | } else { |
3513 | sset_add(&ofproto->ports, devname); | |
3514 | } | |
3515 | return 0; | |
3516 | } | |
3517 | ||
abe529af | 3518 | static int |
4e022ec0 | 3519 | port_del(struct ofproto *ofproto_, ofp_port_t ofp_port) |
abe529af BP |
3520 | { |
3521 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
e672ff9b | 3522 | struct ofport_dpif *ofport = ofp_port_to_ofport(ofproto, ofp_port); |
e1b1d06a | 3523 | int error = 0; |
abe529af | 3524 | |
b9ad7294 EJ |
3525 | if (!ofport) { |
3526 | return 0; | |
e1b1d06a | 3527 | } |
b9ad7294 EJ |
3528 | |
3529 | sset_find_and_delete(&ofproto->ghost_ports, | |
3530 | netdev_get_name(ofport->up.netdev)); | |
a614d823 | 3531 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
8911c674 | 3532 | if (!ofport->is_tunnel && !netdev_vport_is_patch(ofport->up.netdev)) { |
b9ad7294 EJ |
3533 | error = dpif_port_del(ofproto->backer->dpif, ofport->odp_port); |
3534 | if (!error) { | |
abe529af BP |
3535 | /* The caller is going to close ofport->up.netdev. If this is a |
3536 | * bonded port, then the bond is using that netdev, so remove it | |
3537 | * from the bond. The client will need to reconfigure everything | |
3538 | * after deleting ports, so then the slave will get re-added. */ | |
3539 | bundle_remove(&ofport->up); | |
3540 | } | |
3541 | } | |
3542 | return error; | |
3543 | } | |
3544 | ||
91364d18 IM |
3545 | static int |
3546 | port_set_config(const struct ofport *ofport_, const struct smap *cfg) | |
3547 | { | |
3548 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
3549 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); | |
3550 | ||
3551 | if (sset_contains(&ofproto->ghost_ports, | |
3552 | netdev_get_name(ofport->up.netdev))) { | |
3553 | return 0; | |
3554 | } | |
3555 | ||
3556 | return dpif_port_set_config(ofproto->backer->dpif, ofport->odp_port, cfg); | |
3557 | } | |
3558 | ||
6527c598 PS |
3559 | static int |
3560 | port_get_stats(const struct ofport *ofport_, struct netdev_stats *stats) | |
3561 | { | |
3562 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
3563 | int error; | |
3564 | ||
3565 | error = netdev_get_stats(ofport->up.netdev, stats); | |
3566 | ||
ee382d89 | 3567 | if (!error && ofport_->ofp_port == OFPP_LOCAL) { |
6527c598 PS |
3568 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); |
3569 | ||
0da3c61b | 3570 | ovs_mutex_lock(&ofproto->stats_mutex); |
6527c598 PS |
3571 | /* ofproto->stats.tx_packets represents packets that we created |
3572 | * internally and sent to some port (e.g. packets sent with | |
91d6cd12 AW |
3573 | * ofproto_dpif_send_packet()). Account for them as if they had |
3574 | * come from OFPP_LOCAL and got forwarded. */ | |
6527c598 PS |
3575 | |
3576 | if (stats->rx_packets != UINT64_MAX) { | |
3577 | stats->rx_packets += ofproto->stats.tx_packets; | |
3578 | } | |
3579 | ||
3580 | if (stats->rx_bytes != UINT64_MAX) { | |
3581 | stats->rx_bytes += ofproto->stats.tx_bytes; | |
3582 | } | |
3583 | ||
3584 | /* ofproto->stats.rx_packets represents packets that were received on | |
3585 | * some port and we processed internally and dropped (e.g. STP). | |
4e090bc7 | 3586 | * Account for them as if they had been forwarded to OFPP_LOCAL. */ |
6527c598 PS |
3587 | |
3588 | if (stats->tx_packets != UINT64_MAX) { | |
3589 | stats->tx_packets += ofproto->stats.rx_packets; | |
3590 | } | |
3591 | ||
3592 | if (stats->tx_bytes != UINT64_MAX) { | |
3593 | stats->tx_bytes += ofproto->stats.rx_bytes; | |
3594 | } | |
0da3c61b | 3595 | ovs_mutex_unlock(&ofproto->stats_mutex); |
6527c598 PS |
3596 | } |
3597 | ||
3598 | return error; | |
3599 | } | |
3600 | ||
50b9699f NM |
3601 | static int |
3602 | port_get_lacp_stats(const struct ofport *ofport_, struct lacp_slave_stats *stats) | |
3603 | { | |
3604 | struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
3605 | if (ofport->bundle && ofport->bundle->lacp) { | |
3606 | if (lacp_get_slave_stats(ofport->bundle->lacp, ofport, stats)) { | |
3607 | return 0; | |
3608 | } | |
3609 | } | |
3610 | return -1; | |
3611 | } | |
3612 | ||
abe529af | 3613 | struct port_dump_state { |
bfbcebc2 | 3614 | struct sset_position pos; |
0a740f48 | 3615 | bool ghost; |
da78d43d BP |
3616 | |
3617 | struct ofproto_port port; | |
3618 | bool has_port; | |
abe529af BP |
3619 | }; |
3620 | ||
3621 | static int | |
acf60855 | 3622 | port_dump_start(const struct ofproto *ofproto_ OVS_UNUSED, void **statep) |
abe529af | 3623 | { |
0a740f48 | 3624 | *statep = xzalloc(sizeof(struct port_dump_state)); |
abe529af BP |
3625 | return 0; |
3626 | } | |
3627 | ||
3628 | static int | |
b9ad7294 | 3629 | port_dump_next(const struct ofproto *ofproto_, void *state_, |
abe529af BP |
3630 | struct ofproto_port *port) |
3631 | { | |
e1b1d06a | 3632 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); |
abe529af | 3633 | struct port_dump_state *state = state_; |
0a740f48 | 3634 | const struct sset *sset; |
acf60855 | 3635 | struct sset_node *node; |
abe529af | 3636 | |
da78d43d BP |
3637 | if (state->has_port) { |
3638 | ofproto_port_destroy(&state->port); | |
3639 | state->has_port = false; | |
3640 | } | |
0a740f48 | 3641 | sset = state->ghost ? &ofproto->ghost_ports : &ofproto->ports; |
bfbcebc2 | 3642 | while ((node = sset_at_position(sset, &state->pos))) { |
acf60855 JP |
3643 | int error; |
3644 | ||
da78d43d BP |
3645 | error = port_query_by_name(ofproto_, node->name, &state->port); |
3646 | if (!error) { | |
3647 | *port = state->port; | |
3648 | state->has_port = true; | |
3649 | return 0; | |
3650 | } else if (error != ENODEV) { | |
acf60855 JP |
3651 | return error; |
3652 | } | |
abe529af | 3653 | } |
acf60855 | 3654 | |
0a740f48 EJ |
3655 | if (!state->ghost) { |
3656 | state->ghost = true; | |
bfbcebc2 | 3657 | memset(&state->pos, 0, sizeof state->pos); |
0a740f48 EJ |
3658 | return port_dump_next(ofproto_, state_, port); |
3659 | } | |
3660 | ||
acf60855 | 3661 | return EOF; |
abe529af BP |
3662 | } |
3663 | ||
3664 | static int | |
3665 | port_dump_done(const struct ofproto *ofproto_ OVS_UNUSED, void *state_) | |
3666 | { | |
3667 | struct port_dump_state *state = state_; | |
3668 | ||
da78d43d BP |
3669 | if (state->has_port) { |
3670 | ofproto_port_destroy(&state->port); | |
3671 | } | |
abe529af BP |
3672 | free(state); |
3673 | return 0; | |
3674 | } | |
3675 | ||
3676 | static int | |
3677 | port_poll(const struct ofproto *ofproto_, char **devnamep) | |
3678 | { | |
3679 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
acf60855 JP |
3680 | |
3681 | if (ofproto->port_poll_errno) { | |
3682 | int error = ofproto->port_poll_errno; | |
3683 | ofproto->port_poll_errno = 0; | |
3684 | return error; | |
3685 | } | |
3686 | ||
3687 | if (sset_is_empty(&ofproto->port_poll_set)) { | |
3688 | return EAGAIN; | |
3689 | } | |
3690 | ||
3691 | *devnamep = sset_pop(&ofproto->port_poll_set); | |
3692 | return 0; | |
abe529af BP |
3693 | } |
3694 | ||
3695 | static void | |
3696 | port_poll_wait(const struct ofproto *ofproto_) | |
3697 | { | |
3698 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
acf60855 | 3699 | dpif_port_poll_wait(ofproto->backer->dpif); |
abe529af BP |
3700 | } |
3701 | ||
3702 | static int | |
3703 | port_is_lacp_current(const struct ofport *ofport_) | |
3704 | { | |
3705 | const struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); | |
3706 | return (ofport->bundle && ofport->bundle->lacp | |
3707 | ? lacp_slave_is_current(ofport->bundle->lacp, ofport) | |
3708 | : -1); | |
3709 | } | |
3710 | \f | |
e79a6c83 EJ |
3711 | /* If 'rule' is an OpenFlow rule, that has expired according to OpenFlow rules, |
3712 | * then delete it entirely. */ | |
3713 | static void | |
f5857865 | 3714 | rule_expire(struct rule_dpif *rule, long long now) |
e79a6c83 | 3715 | OVS_REQUIRES(ofproto_mutex) |
9d6ac44e | 3716 | { |
dc437090 | 3717 | uint16_t hard_timeout, idle_timeout; |
dc437090 | 3718 | int reason = -1; |
9d6ac44e | 3719 | |
e79a6c83 EJ |
3720 | hard_timeout = rule->up.hard_timeout; |
3721 | idle_timeout = rule->up.idle_timeout; | |
dc437090 JR |
3722 | |
3723 | /* Has 'rule' expired? */ | |
3724 | if (hard_timeout) { | |
3725 | long long int modified; | |
3726 | ||
3727 | ovs_mutex_lock(&rule->up.mutex); | |
3728 | modified = rule->up.modified; | |
3729 | ovs_mutex_unlock(&rule->up.mutex); | |
3730 | ||
3731 | if (now > modified + hard_timeout * 1000) { | |
3732 | reason = OFPRR_HARD_TIMEOUT; | |
3733 | } | |
3734 | } | |
3735 | ||
3736 | if (reason < 0 && idle_timeout) { | |
3737 | long long int used; | |
3738 | ||
3739 | ovs_mutex_lock(&rule->stats_mutex); | |
1a4ec18d | 3740 | used = rule->stats.used; |
dc437090 JR |
3741 | ovs_mutex_unlock(&rule->stats_mutex); |
3742 | ||
3743 | if (now > used + idle_timeout * 1000) { | |
3744 | reason = OFPRR_IDLE_TIMEOUT; | |
3745 | } | |
f9c37233 | 3746 | } |
501f8d1f | 3747 | |
e79a6c83 EJ |
3748 | if (reason >= 0) { |
3749 | COVERAGE_INC(ofproto_dpif_expired); | |
3750 | ofproto_rule_expire(&rule->up, reason); | |
a41d7bf2 | 3751 | } |
e79a6c83 | 3752 | } |
a41d7bf2 | 3753 | |
1df7f7aa NS |
3754 | static void |
3755 | ofproto_dpif_set_packet_odp_port(const struct ofproto_dpif *ofproto, | |
3756 | ofp_port_t in_port, struct dp_packet *packet) | |
3757 | { | |
3758 | if (in_port == OFPP_NONE) { | |
3759 | in_port = OFPP_LOCAL; | |
3760 | } | |
3761 | packet->md.in_port.odp_port = ofp_port_to_odp_port(ofproto, in_port); | |
3762 | } | |
3763 | ||
e79a6c83 | 3764 | int |
cdd42eda JG |
3765 | ofproto_dpif_execute_actions__(struct ofproto_dpif *ofproto, |
3766 | const struct flow *flow, | |
3767 | struct rule_dpif *rule, | |
3768 | const struct ofpact *ofpacts, size_t ofpacts_len, | |
790c5d26 | 3769 | int indentation, int depth, int resubmits, |
cdd42eda | 3770 | struct dp_packet *packet) |
e79a6c83 | 3771 | { |
e79a6c83 EJ |
3772 | struct dpif_flow_stats stats; |
3773 | struct xlate_out xout; | |
3774 | struct xlate_in xin; | |
758c456d | 3775 | struct dpif_execute execute; |
e79a6c83 | 3776 | int error; |
f9c37233 | 3777 | |
e79a6c83 | 3778 | ovs_assert((rule != NULL) != (ofpacts != NULL)); |
501f8d1f | 3779 | |
e79a6c83 | 3780 | dpif_flow_stats_extract(flow, packet, time_msec(), &stats); |
adcf00ba | 3781 | |
e79a6c83 EJ |
3782 | if (rule) { |
3783 | rule_dpif_credit_stats(rule, &stats); | |
3784 | } | |
c84451a6 | 3785 | |
1520ef4f BP |
3786 | uint64_t odp_actions_stub[1024 / 8]; |
3787 | struct ofpbuf odp_actions = OFPBUF_STUB_INITIALIZER(odp_actions_stub); | |
cc377352 | 3788 | xlate_in_init(&xin, ofproto, flow, flow->in_port.ofp_port, rule, |
1520ef4f | 3789 | stats.tcp_flags, packet, NULL, &odp_actions); |
e79a6c83 EJ |
3790 | xin.ofpacts = ofpacts; |
3791 | xin.ofpacts_len = ofpacts_len; | |
3792 | xin.resubmit_stats = &stats; | |
9a9b001a | 3793 | xin.indentation = indentation; |
790c5d26 | 3794 | xin.depth = depth; |
cdd42eda | 3795 | xin.resubmits = resubmits; |
fff1b9c0 JR |
3796 | if (xlate_actions(&xin, &xout) != XLATE_OK) { |
3797 | error = EINVAL; | |
3798 | goto out; | |
3799 | } | |
d445cc16 | 3800 | |
1520ef4f BP |
3801 | execute.actions = odp_actions.data; |
3802 | execute.actions_len = odp_actions.size; | |
a36de779 | 3803 | |
cf62fa4c | 3804 | pkt_metadata_from_flow(&packet->md, flow); |
08edf837 | 3805 | execute.packet = packet; |
1cceb31b | 3806 | execute.flow = flow; |
08edf837 | 3807 | execute.needs_help = (xout.slow & SLOW_ACTION) != 0; |
43f9ac0a | 3808 | execute.probe = false; |
27130224 | 3809 | execute.mtu = 0; |
08edf837 BP |
3810 | |
3811 | /* Fix up in_port. */ | |
1df7f7aa | 3812 | ofproto_dpif_set_packet_odp_port(ofproto, flow->in_port.ofp_port, packet); |
758c456d JR |
3813 | |
3814 | error = dpif_execute(ofproto->backer->dpif, &execute); | |
fff1b9c0 | 3815 | out: |
e79a6c83 | 3816 | xlate_out_uninit(&xout); |
1520ef4f | 3817 | ofpbuf_uninit(&odp_actions); |
9d6ac44e | 3818 | |
e79a6c83 | 3819 | return error; |
9d6ac44e BP |
3820 | } |
3821 | ||
cdd42eda JG |
3822 | /* Executes, within 'ofproto', the actions in 'rule' or 'ofpacts' on 'packet'. |
3823 | * 'flow' must reflect the data in 'packet'. */ | |
3824 | int | |
3825 | ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto, | |
3826 | const struct flow *flow, | |
3827 | struct rule_dpif *rule, | |
3828 | const struct ofpact *ofpacts, size_t ofpacts_len, | |
3829 | struct dp_packet *packet) | |
3830 | { | |
3831 | return ofproto_dpif_execute_actions__(ofproto, flow, rule, ofpacts, | |
790c5d26 | 3832 | ofpacts_len, 0, 0, 0, packet); |
cdd42eda JG |
3833 | } |
3834 | ||
e79a6c83 EJ |
3835 | void |
3836 | rule_dpif_credit_stats(struct rule_dpif *rule, | |
3837 | const struct dpif_flow_stats *stats) | |
8f73d537 | 3838 | { |
e79a6c83 | 3839 | ovs_mutex_lock(&rule->stats_mutex); |
39c94593 JR |
3840 | if (OVS_UNLIKELY(rule->new_rule)) { |
3841 | rule_dpif_credit_stats(rule->new_rule, stats); | |
3842 | } else { | |
3843 | rule->stats.n_packets += stats->n_packets; | |
3844 | rule->stats.n_bytes += stats->n_bytes; | |
3845 | rule->stats.used = MAX(rule->stats.used, stats->used); | |
3846 | } | |
e79a6c83 | 3847 | ovs_mutex_unlock(&rule->stats_mutex); |
8f73d537 EJ |
3848 | } |
3849 | ||
e79a6c83 EJ |
3850 | ovs_be64 |
3851 | rule_dpif_get_flow_cookie(const struct rule_dpif *rule) | |
3852 | OVS_REQUIRES(rule->up.mutex) | |
3853 | { | |
3854 | return rule->up.flow_cookie; | |
3855 | } | |
cfd5c9eb | 3856 | |
e79a6c83 EJ |
3857 | void |
3858 | rule_dpif_reduce_timeouts(struct rule_dpif *rule, uint16_t idle_timeout, | |
3859 | uint16_t hard_timeout) | |
3860 | { | |
3861 | ofproto_rule_reduce_timeouts(&rule->up, idle_timeout, hard_timeout); | |
6a7e895f BP |
3862 | } |
3863 | ||
d8227eba JR |
3864 | /* Returns 'rule''s actions. The returned actions are RCU-protected, and can |
3865 | * be read until the calling thread quiesces. */ | |
dc723c44 | 3866 | const struct rule_actions * |
e79a6c83 | 3867 | rule_dpif_get_actions(const struct rule_dpif *rule) |
6ff686f2 | 3868 | { |
e79a6c83 EJ |
3869 | return rule_get_actions(&rule->up); |
3870 | } | |
abe529af | 3871 | |
888ac0d7 SH |
3872 | /* Sets 'rule''s recirculation id. */ |
3873 | static void | |
3874 | rule_dpif_set_recirc_id(struct rule_dpif *rule, uint32_t id) | |
3875 | OVS_REQUIRES(rule->up.mutex) | |
3876 | { | |
e672ff9b JR |
3877 | ovs_assert(!rule->recirc_id || rule->recirc_id == id); |
3878 | if (rule->recirc_id == id) { | |
3879 | /* Release the new reference to the same id. */ | |
3880 | recirc_free_id(id); | |
3881 | } else { | |
3882 | rule->recirc_id = id; | |
888ac0d7 | 3883 | } |
888ac0d7 SH |
3884 | } |
3885 | ||
3886 | /* Sets 'rule''s recirculation id. */ | |
3887 | void | |
3888 | rule_set_recirc_id(struct rule *rule_, uint32_t id) | |
3889 | { | |
3890 | struct rule_dpif *rule = rule_dpif_cast(rule_); | |
3891 | ||
3892 | ovs_mutex_lock(&rule->up.mutex); | |
3893 | rule_dpif_set_recirc_id(rule, id); | |
3894 | ovs_mutex_unlock(&rule->up.mutex); | |
3895 | } | |
3896 | ||
44e0c35d | 3897 | ovs_version_t |
39c94593 | 3898 | ofproto_dpif_get_tables_version(struct ofproto_dpif *ofproto OVS_UNUSED) |
621b8064 | 3899 | { |
44e0c35d | 3900 | ovs_version_t version; |
621b8064 JR |
3901 | |
3902 | atomic_read_relaxed(&ofproto->tables_version, &version); | |
39c94593 | 3903 | |
621b8064 JR |
3904 | return version; |
3905 | } | |
3906 | ||
34dd0d78 | 3907 | /* The returned rule (if any) is valid at least until the next RCU quiescent |
1e1e1d19 BP |
3908 | * period. If the rule needs to stay around longer, the caller should take |
3909 | * a reference. | |
2e0bded4 BP |
3910 | * |
3911 | * 'flow' is non-const to allow for temporary modifications during the lookup. | |
3912 | * Any changes are restored before returning. */ | |
6d328fa2 | 3913 | static struct rule_dpif * |
44e0c35d | 3914 | rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, ovs_version_t version, |
621b8064 | 3915 | uint8_t table_id, struct flow *flow, |
1e1e1d19 | 3916 | struct flow_wildcards *wc) |
abe529af | 3917 | { |
6d328fa2 | 3918 | struct classifier *cls = &ofproto->up.tables[table_id].cls; |
1e1e1d19 BP |
3919 | return rule_dpif_cast(rule_from_cls_rule(classifier_lookup(cls, version, |
3920 | flow, wc))); | |
6d328fa2 SH |
3921 | } |
3922 | ||
39c94593 JR |
3923 | /* Look up 'flow' in 'ofproto''s classifier version 'version', starting from |
3924 | * table '*table_id'. Returns the rule that was found, which may be one of the | |
3925 | * special rules according to packet miss hadling. If 'may_packet_in' is | |
3926 | * false, returning of the miss_rule (which issues packet ins for the | |
3927 | * controller) is avoided. Updates 'wc', if nonnull, to reflect the fields | |
3928 | * that were used during the lookup. | |
6d328fa2 SH |
3929 | * |
3930 | * If 'honor_table_miss' is true, the first lookup occurs in '*table_id', but | |
3931 | * if none is found then the table miss configuration for that table is | |
3932 | * honored, which can result in additional lookups in other OpenFlow tables. | |
3933 | * In this case the function updates '*table_id' to reflect the final OpenFlow | |
3934 | * table that was searched. | |
3935 | * | |
3936 | * If 'honor_table_miss' is false, then only one table lookup occurs, in | |
3937 | * '*table_id'. | |
3938 | * | |
1a7c0cd7 | 3939 | * The rule is returned in '*rule', which is valid at least until the next |
1e1e1d19 BP |
3940 | * RCU quiescent period. If the '*rule' needs to stay around longer, the |
3941 | * caller must take a reference. | |
34dd0d78 JR |
3942 | * |
3943 | * 'in_port' allows the lookup to take place as if the in port had the value | |
2e0bded4 BP |
3944 | * 'in_port'. This is needed for resubmit action support. |
3945 | * | |
3946 | * 'flow' is non-const to allow for temporary modifications during the lookup. | |
3947 | * Any changes are restored before returning. */ | |
34dd0d78 | 3948 | struct rule_dpif * |
18721c4a | 3949 | rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto, |
44e0c35d | 3950 | ovs_version_t version, struct flow *flow, |
1e1e1d19 | 3951 | struct flow_wildcards *wc, |
18721c4a | 3952 | const struct dpif_flow_stats *stats, |
34dd0d78 JR |
3953 | uint8_t *table_id, ofp_port_t in_port, |
3954 | bool may_packet_in, bool honor_table_miss) | |
6d328fa2 | 3955 | { |
d8227eba | 3956 | ovs_be16 old_tp_src = flow->tp_src, old_tp_dst = flow->tp_dst; |
34dd0d78 JR |
3957 | ofp_port_t old_in_port = flow->in_port.ofp_port; |
3958 | enum ofputil_table_miss miss_config; | |
3959 | struct rule_dpif *rule; | |
6d328fa2 SH |
3960 | uint8_t next_id; |
3961 | ||
d8227eba JR |
3962 | /* We always unwildcard nw_frag (for IP), so they |
3963 | * need not be unwildcarded here. */ | |
3964 | if (flow->nw_frag & FLOW_NW_FRAG_ANY | |
ad99e2ed BP |
3965 | && ofproto->up.frag_handling != OFPUTIL_FRAG_NX_MATCH) { |
3966 | if (ofproto->up.frag_handling == OFPUTIL_FRAG_NORMAL) { | |
d8227eba JR |
3967 | /* We must pretend that transport ports are unavailable. */ |
3968 | flow->tp_src = htons(0); | |
3969 | flow->tp_dst = htons(0); | |
3970 | } else { | |
ad99e2ed | 3971 | /* Must be OFPUTIL_FRAG_DROP (we don't have OFPUTIL_FRAG_REASM). |
d8227eba | 3972 | * Use the drop_frags_rule (which cannot disappear). */ |
34dd0d78 | 3973 | rule = ofproto->drop_frags_rule; |
d8227eba JR |
3974 | if (stats) { |
3975 | struct oftable *tbl = &ofproto->up.tables[*table_id]; | |
3976 | unsigned long orig; | |
3977 | ||
3978 | atomic_add_relaxed(&tbl->n_matched, stats->n_packets, &orig); | |
3979 | } | |
34dd0d78 | 3980 | return rule; |
d8227eba JR |
3981 | } |
3982 | } | |
3983 | ||
34dd0d78 JR |
3984 | /* Look up a flow with 'in_port' as the input port. Then restore the |
3985 | * original input port (otherwise OFPP_NORMAL and OFPP_IN_PORT will | |
3986 | * have surprising behavior). */ | |
3987 | flow->in_port.ofp_port = in_port; | |
3988 | ||
3989 | /* Our current implementation depends on n_tables == N_TABLES, and | |
3990 | * TBL_INTERNAL being the last table. */ | |
3991 | BUILD_ASSERT_DECL(N_TABLES == TBL_INTERNAL + 1); | |
3992 | ||
3993 | miss_config = OFPUTIL_TABLE_MISS_CONTINUE; | |
d8227eba | 3994 | |
6d328fa2 SH |
3995 | for (next_id = *table_id; |
3996 | next_id < ofproto->up.n_tables; | |
3997 | next_id++, next_id += (next_id == TBL_INTERNAL)) | |
3998 | { | |
3999 | *table_id = next_id; | |
1e1e1d19 | 4000 | rule = rule_dpif_lookup_in_table(ofproto, version, next_id, flow, wc); |
d611866c SH |
4001 | if (stats) { |
4002 | struct oftable *tbl = &ofproto->up.tables[next_id]; | |
d611866c | 4003 | unsigned long orig; |
afcea9ea | 4004 | |
34dd0d78 | 4005 | atomic_add_relaxed(rule ? &tbl->n_matched : &tbl->n_missed, |
afcea9ea | 4006 | stats->n_packets, &orig); |
d611866c | 4007 | } |
34dd0d78 JR |
4008 | if (rule) { |
4009 | goto out; /* Match. */ | |
4010 | } | |
4011 | if (honor_table_miss) { | |
4012 | miss_config = ofproto_table_get_miss_config(&ofproto->up, | |
4013 | *table_id); | |
4014 | if (miss_config == OFPUTIL_TABLE_MISS_CONTINUE) { | |
4015 | continue; | |
4016 | } | |
4017 | } | |
4018 | break; | |
4019 | } | |
4020 | /* Miss. */ | |
4021 | rule = ofproto->no_packet_in_rule; | |
4022 | if (may_packet_in) { | |
4023 | if (miss_config == OFPUTIL_TABLE_MISS_CONTINUE | |
4024 | || miss_config == OFPUTIL_TABLE_MISS_CONTROLLER) { | |
4025 | struct ofport_dpif *port; | |
4026 | ||
e672ff9b | 4027 | port = ofp_port_to_ofport(ofproto, old_in_port); |
34dd0d78 JR |
4028 | if (!port) { |
4029 | VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16, | |
4030 | old_in_port); | |
4031 | } else if (!(port->up.pp.config & OFPUTIL_PC_NO_PACKET_IN)) { | |
4032 | rule = ofproto->miss_rule; | |
6d328fa2 | 4033 | } |
34dd0d78 JR |
4034 | } else if (miss_config == OFPUTIL_TABLE_MISS_DEFAULT && |
4035 | connmgr_wants_packet_in_on_miss(ofproto->up.connmgr)) { | |
4036 | rule = ofproto->miss_rule; | |
6d328fa2 SH |
4037 | } |
4038 | } | |
d8227eba JR |
4039 | out: |
4040 | /* Restore port numbers, as they may have been modified above. */ | |
4041 | flow->tp_src = old_tp_src; | |
4042 | flow->tp_dst = old_tp_dst; | |
34dd0d78 JR |
4043 | /* Restore the old in port. */ |
4044 | flow->in_port.ofp_port = old_in_port; | |
6d328fa2 | 4045 | |
34dd0d78 | 4046 | return rule; |
a2143702 BP |
4047 | } |
4048 | ||
70742c7f EJ |
4049 | static struct rule_dpif *rule_dpif_cast(const struct rule *rule) |
4050 | { | |
4051 | return rule ? CONTAINER_OF(rule, struct rule_dpif, up) : NULL; | |
4052 | } | |
4053 | ||
abe529af BP |
4054 | static struct rule * |
4055 | rule_alloc(void) | |
4056 | { | |
3da29e32 | 4057 | struct rule_dpif *rule = xzalloc(sizeof *rule); |
abe529af BP |
4058 | return &rule->up; |
4059 | } | |
4060 | ||
4061 | static void | |
4062 | rule_dealloc(struct rule *rule_) | |
4063 | { | |
4064 | struct rule_dpif *rule = rule_dpif_cast(rule_); | |
4065 | free(rule); | |
4066 | } | |
4067 | ||
07659514 | 4068 | static enum ofperr |
1b43cf9e | 4069 | check_mask(struct ofproto_dpif *ofproto, const struct miniflow *flow) |
07659514 | 4070 | { |
95619d8c | 4071 | const struct odp_support *support; |
07659514 | 4072 | uint16_t ct_state, ct_zone; |
efba5ae4 | 4073 | ovs_u128 ct_label; |
8e53fe8c | 4074 | uint32_t ct_mark; |
07659514 | 4075 | |
95619d8c | 4076 | support = &ofproto_dpif_get_support(ofproto)->odp; |
1b43cf9e | 4077 | ct_state = MINIFLOW_GET_U16(flow, ct_state); |
11968381 | 4078 | if (support->ct_state && support->ct_zone && support->ct_mark |
7b27258c | 4079 | && support->ct_label && support->ct_state_nat) { |
11968381 JS |
4080 | return ct_state & CS_UNSUPPORTED_MASK ? OFPERR_OFPBMC_BAD_MASK : 0; |
4081 | } | |
4082 | ||
1b43cf9e JS |
4083 | ct_zone = MINIFLOW_GET_U16(flow, ct_zone); |
4084 | ct_mark = MINIFLOW_GET_U32(flow, ct_mark); | |
4085 | ct_label = MINIFLOW_GET_U128(flow, ct_label); | |
07659514 | 4086 | |
95619d8c JS |
4087 | if ((ct_state && !support->ct_state) |
4088 | || (ct_state & CS_UNSUPPORTED_MASK) | |
7b27258c | 4089 | || ((ct_state & (CS_SRC_NAT | CS_DST_NAT)) && !support->ct_state_nat) |
95619d8c JS |
4090 | || (ct_zone && !support->ct_zone) |
4091 | || (ct_mark && !support->ct_mark) | |
2ff8484b | 4092 | || (!ovs_u128_is_zero(ct_label) && !support->ct_label)) { |
95619d8c | 4093 | return OFPERR_OFPBMC_BAD_MASK; |
07659514 | 4094 | } |
95619d8c | 4095 | |
07659514 JS |
4096 | return 0; |
4097 | } | |
4098 | ||
1b43cf9e JS |
4099 | static enum ofperr |
4100 | check_actions(const struct ofproto_dpif *ofproto, | |
4101 | const struct rule_actions *const actions) | |
4102 | { | |
4103 | const struct ofpact *ofpact; | |
4104 | ||
4105 | OFPACT_FOR_EACH (ofpact, actions->ofpacts, actions->ofpacts_len) { | |
4106 | const struct odp_support *support; | |
4107 | const struct ofpact_conntrack *ct; | |
4108 | const struct ofpact *a; | |
4109 | ||
4110 | if (ofpact->type != OFPACT_CT) { | |
4111 | continue; | |
4112 | } | |
4113 | ||
4114 | ct = CONTAINER_OF(ofpact, struct ofpact_conntrack, ofpact); | |
4115 | support = &ofproto_dpif_get_support(ofproto)->odp; | |
4116 | ||
4117 | if (!support->ct_state) { | |
4118 | return OFPERR_OFPBAC_BAD_TYPE; | |
4119 | } | |
4120 | if ((ct->zone_imm || ct->zone_src.field) && !support->ct_zone) { | |
4121 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
4122 | } | |
4123 | ||
4124 | OFPACT_FOR_EACH(a, ct->actions, ofpact_ct_get_action_len(ct)) { | |
4125 | const struct mf_field *dst = ofpact_get_mf_dst(a); | |
4126 | ||
7b27258c DDP |
4127 | if (a->type == OFPACT_NAT && !support->ct_state_nat) { |
4128 | /* The backer doesn't seem to support the NAT bits in | |
4129 | * 'ct_state': assume that it doesn't support the NAT | |
4130 | * action. */ | |
4131 | return OFPERR_OFPBAC_BAD_TYPE; | |
4132 | } | |
1b43cf9e JS |
4133 | if (dst && ((dst->id == MFF_CT_MARK && !support->ct_mark) |
4134 | || (dst->id == MFF_CT_LABEL && !support->ct_label))) { | |
4135 | return OFPERR_OFPBAC_BAD_SET_ARGUMENT; | |
4136 | } | |
4137 | } | |
4138 | } | |
4139 | ||
4140 | return 0; | |
4141 | } | |
4142 | ||
4143 | static enum ofperr | |
4144 | rule_check(struct rule *rule) | |
4145 | { | |
4146 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->ofproto); | |
4147 | enum ofperr err; | |
4148 | ||
4149 | err = check_mask(ofproto, &rule->cr.match.mask->masks); | |
4150 | if (err) { | |
4151 | return err; | |
4152 | } | |
4153 | return check_actions(ofproto, rule->actions); | |
4154 | } | |
4155 | ||
90bf1e07 | 4156 | static enum ofperr |
abe529af | 4157 | rule_construct(struct rule *rule_) |
dc437090 | 4158 | OVS_NO_THREAD_SAFETY_ANALYSIS |
abe529af BP |
4159 | { |
4160 | struct rule_dpif *rule = rule_dpif_cast(rule_); | |
07659514 JS |
4161 | int error; |
4162 | ||
4163 | error = rule_check(rule_); | |
4164 | if (error) { | |
4165 | return error; | |
4166 | } | |
4167 | ||
97ba2d36 | 4168 | ovs_mutex_init_adaptive(&rule->stats_mutex); |
1a4ec18d JS |
4169 | rule->stats.n_packets = 0; |
4170 | rule->stats.n_bytes = 0; | |
4171 | rule->stats.used = rule->up.modified; | |
888ac0d7 | 4172 | rule->recirc_id = 0; |
39c94593 | 4173 | rule->new_rule = NULL; |
888ac0d7 | 4174 | |
abe529af BP |
4175 | return 0; |
4176 | } | |
4177 | ||
39c94593 JR |
4178 | static void |
4179 | rule_insert(struct rule *rule_, struct rule *old_rule_, bool forward_stats) | |
15aaf599 | 4180 | OVS_REQUIRES(ofproto_mutex) |
abe529af | 4181 | { |
9fbe253e | 4182 | struct rule_dpif *rule = rule_dpif_cast(rule_); |
39c94593 JR |
4183 | |
4184 | if (old_rule_ && forward_stats) { | |
4185 | struct rule_dpif *old_rule = rule_dpif_cast(old_rule_); | |
4186 | ||
4187 | ovs_assert(!old_rule->new_rule); | |
4188 | ||
4189 | /* Take a reference to the new rule, and refer all stats updates from | |
4190 | * the old rule to the new rule. */ | |
4191 | rule_dpif_ref(rule); | |
4192 | ||
4193 | ovs_mutex_lock(&old_rule->stats_mutex); | |
4194 | ovs_mutex_lock(&rule->stats_mutex); | |
4195 | old_rule->new_rule = rule; /* Forward future stats. */ | |
4196 | rule->stats = old_rule->stats; /* Transfer stats to the new rule. */ | |
4197 | ovs_mutex_unlock(&rule->stats_mutex); | |
4198 | ovs_mutex_unlock(&old_rule->stats_mutex); | |
4199 | } | |
8037acb4 BP |
4200 | } |
4201 | ||
4202 | static void | |
4203 | rule_destruct(struct rule *rule_) | |
39c94593 | 4204 | OVS_NO_THREAD_SAFETY_ANALYSIS |
8037acb4 BP |
4205 | { |
4206 | struct rule_dpif *rule = rule_dpif_cast(rule_); | |
888ac0d7 | 4207 | |
9fbe253e | 4208 | ovs_mutex_destroy(&rule->stats_mutex); |
39c94593 JR |
4209 | /* Release reference to the new rule, if any. */ |
4210 | if (rule->new_rule) { | |
4211 | rule_dpif_unref(rule->new_rule); | |
4212 | } | |
888ac0d7 | 4213 | if (rule->recirc_id) { |
e672ff9b | 4214 | recirc_free_id(rule->recirc_id); |
888ac0d7 | 4215 | } |
abe529af BP |
4216 | } |
4217 | ||
4218 | static void | |
dc437090 JR |
4219 | rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes, |
4220 | long long int *used) | |
abe529af BP |
4221 | { |
4222 | struct rule_dpif *rule = rule_dpif_cast(rule_); | |
abe529af | 4223 | |
9fbe253e | 4224 | ovs_mutex_lock(&rule->stats_mutex); |
39c94593 JR |
4225 | if (OVS_UNLIKELY(rule->new_rule)) { |
4226 | rule_get_stats(&rule->new_rule->up, packets, bytes, used); | |
4227 | } else { | |
4228 | *packets = rule->stats.n_packets; | |
4229 | *bytes = rule->stats.n_bytes; | |
4230 | *used = rule->stats.used; | |
4231 | } | |
9fbe253e | 4232 | ovs_mutex_unlock(&rule->stats_mutex); |
abe529af BP |
4233 | } |
4234 | ||
0a740f48 EJ |
4235 | static void |
4236 | rule_dpif_execute(struct rule_dpif *rule, const struct flow *flow, | |
cf62fa4c | 4237 | struct dp_packet *packet) |
abe529af | 4238 | { |
419460f4 AW |
4239 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto); |
4240 | ||
4241 | ofproto_dpif_execute_actions(ofproto, flow, rule, NULL, 0, packet); | |
0a740f48 | 4242 | } |
5bf0e941 | 4243 | |
0a740f48 EJ |
4244 | static enum ofperr |
4245 | rule_execute(struct rule *rule, const struct flow *flow, | |
cf62fa4c | 4246 | struct dp_packet *packet) |
0a740f48 EJ |
4247 | { |
4248 | rule_dpif_execute(rule_dpif_cast(rule), flow, packet); | |
cf62fa4c | 4249 | dp_packet_delete(packet); |
5bf0e941 | 4250 | return 0; |
abe529af BP |
4251 | } |
4252 | ||
00430a3f SH |
4253 | static struct group_dpif *group_dpif_cast(const struct ofgroup *group) |
4254 | { | |
4255 | return group ? CONTAINER_OF(group, struct group_dpif, up) : NULL; | |
4256 | } | |
4257 | ||
4258 | static struct ofgroup * | |
4259 | group_alloc(void) | |
4260 | { | |
4261 | struct group_dpif *group = xzalloc(sizeof *group); | |
4262 | return &group->up; | |
4263 | } | |
4264 | ||
4265 | static void | |
4266 | group_dealloc(struct ofgroup *group_) | |
4267 | { | |
4268 | struct group_dpif *group = group_dpif_cast(group_); | |
4269 | free(group); | |
4270 | } | |
4271 | ||
4272 | static void | |
4273 | group_construct_stats(struct group_dpif *group) | |
4274 | OVS_REQUIRES(group->stats_mutex) | |
4275 | { | |
1e684d7d | 4276 | struct ofputil_bucket *bucket; |
ca6ba700 | 4277 | const struct ovs_list *buckets; |
1e684d7d | 4278 | |
00430a3f SH |
4279 | group->packet_count = 0; |
4280 | group->byte_count = 0; | |
1e684d7d | 4281 | |
db88b35c | 4282 | buckets = group_dpif_get_buckets(group); |
1e684d7d RW |
4283 | LIST_FOR_EACH (bucket, list_node, buckets) { |
4284 | bucket->stats.packet_count = 0; | |
4285 | bucket->stats.byte_count = 0; | |
00430a3f SH |
4286 | } |
4287 | } | |
4288 | ||
1e684d7d RW |
4289 | void |
4290 | group_dpif_credit_stats(struct group_dpif *group, | |
4291 | struct ofputil_bucket *bucket, | |
4292 | const struct dpif_flow_stats *stats) | |
4293 | { | |
4294 | ovs_mutex_lock(&group->stats_mutex); | |
4295 | group->packet_count += stats->n_packets; | |
4296 | group->byte_count += stats->n_bytes; | |
4297 | if (bucket) { | |
4298 | bucket->stats.packet_count += stats->n_packets; | |
4299 | bucket->stats.byte_count += stats->n_bytes; | |
4300 | } else { /* Credit to all buckets */ | |
ca6ba700 | 4301 | const struct ovs_list *buckets; |
1e684d7d | 4302 | |
db88b35c | 4303 | buckets = group_dpif_get_buckets(group); |
1e684d7d RW |
4304 | LIST_FOR_EACH (bucket, list_node, buckets) { |
4305 | bucket->stats.packet_count += stats->n_packets; | |
4306 | bucket->stats.byte_count += stats->n_bytes; | |
4307 | } | |
4308 | } | |
4309 | ovs_mutex_unlock(&group->stats_mutex); | |
4310 | } | |
4311 | ||
00430a3f SH |
4312 | static enum ofperr |
4313 | group_construct(struct ofgroup *group_) | |
4314 | { | |
4315 | struct group_dpif *group = group_dpif_cast(group_); | |
5a070238 | 4316 | |
97ba2d36 | 4317 | ovs_mutex_init_adaptive(&group->stats_mutex); |
00430a3f SH |
4318 | ovs_mutex_lock(&group->stats_mutex); |
4319 | group_construct_stats(group); | |
4320 | ovs_mutex_unlock(&group->stats_mutex); | |
4321 | return 0; | |
4322 | } | |
4323 | ||
00430a3f SH |
4324 | static void |
4325 | group_destruct(struct ofgroup *group_) | |
4326 | { | |
4327 | struct group_dpif *group = group_dpif_cast(group_); | |
00430a3f SH |
4328 | ovs_mutex_destroy(&group->stats_mutex); |
4329 | } | |
4330 | ||
2b0b0b80 | 4331 | static void |
809c7548 | 4332 | group_modify(struct ofgroup *group_) |
00430a3f | 4333 | { |
4c9dbc0b | 4334 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(group_->ofproto); |
00430a3f | 4335 | |
4c9dbc0b | 4336 | ofproto->backer->need_revalidate = REV_FLOW_TABLE; |
00430a3f SH |
4337 | } |
4338 | ||
4339 | static enum ofperr | |
4340 | group_get_stats(const struct ofgroup *group_, struct ofputil_group_stats *ogs) | |
4341 | { | |
4342 | struct group_dpif *group = group_dpif_cast(group_); | |
1e684d7d | 4343 | struct ofputil_bucket *bucket; |
ca6ba700 | 4344 | const struct ovs_list *buckets; |
1e684d7d | 4345 | struct bucket_counter *bucket_stats; |
00430a3f | 4346 | |
00430a3f SH |
4347 | ovs_mutex_lock(&group->stats_mutex); |
4348 | ogs->packet_count = group->packet_count; | |
4349 | ogs->byte_count = group->byte_count; | |
1e684d7d | 4350 | |
db88b35c | 4351 | buckets = group_dpif_get_buckets(group); |
1e684d7d RW |
4352 | bucket_stats = ogs->bucket_stats; |
4353 | LIST_FOR_EACH (bucket, list_node, buckets) { | |
4354 | bucket_stats->packet_count = bucket->stats.packet_count; | |
4355 | bucket_stats->byte_count = bucket->stats.byte_count; | |
4356 | bucket_stats++; | |
4357 | } | |
00430a3f SH |
4358 | ovs_mutex_unlock(&group->stats_mutex); |
4359 | ||
4360 | return 0; | |
4361 | } | |
f4fb341b | 4362 | |
809c7548 RW |
4363 | /* If the group exists, this function increments the groups's reference count. |
4364 | * | |
4365 | * Make sure to call group_dpif_unref() after no longer needing to maintain | |
4366 | * a reference to the group. */ | |
db88b35c | 4367 | struct group_dpif * |
76973237 | 4368 | group_dpif_lookup(struct ofproto_dpif *ofproto, uint32_t group_id, |
5d08a275 | 4369 | ovs_version_t version, bool take_ref) |
f4fb341b | 4370 | { |
76973237 | 4371 | struct ofgroup *ofgroup = ofproto_group_lookup(&ofproto->up, group_id, |
5d08a275 | 4372 | version, take_ref); |
db88b35c | 4373 | return ofgroup ? group_dpif_cast(ofgroup) : NULL; |
f4fb341b SH |
4374 | } |
4375 | ||
db88b35c JR |
4376 | const struct ovs_list * |
4377 | group_dpif_get_buckets(const struct group_dpif *group) | |
f4fb341b | 4378 | { |
db88b35c | 4379 | return &group->up.buckets; |
f4fb341b SH |
4380 | } |
4381 | ||
4382 | enum ofp11_group_type | |
4383 | group_dpif_get_type(const struct group_dpif *group) | |
4384 | { | |
4385 | return group->up.type; | |
4386 | } | |
7565c3e4 SH |
4387 | |
4388 | const char * | |
4389 | group_dpif_get_selection_method(const struct group_dpif *group) | |
4390 | { | |
4391 | return group->up.props.selection_method; | |
4392 | } | |
abe529af | 4393 | \f |
2eb79142 JG |
4394 | /* Sends 'packet' out 'ofport'. If 'port' is a tunnel and that tunnel type |
4395 | * supports a notion of an OAM flag, sets it if 'oam' is true. | |
52a90c29 | 4396 | * May modify 'packet'. |
abe529af | 4397 | * Returns 0 if successful, otherwise a positive errno value. */ |
91d6cd12 | 4398 | int |
2eb79142 JG |
4399 | ofproto_dpif_send_packet(const struct ofport_dpif *ofport, bool oam, |
4400 | struct dp_packet *packet) | |
abe529af | 4401 | { |
79e15b78 | 4402 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); |
abe529af BP |
4403 | int error; |
4404 | ||
2eb79142 | 4405 | error = xlate_send_packet(ofport, oam, packet); |
79e15b78 | 4406 | |
0da3c61b | 4407 | ovs_mutex_lock(&ofproto->stats_mutex); |
79e15b78 | 4408 | ofproto->stats.tx_packets++; |
cf62fa4c | 4409 | ofproto->stats.tx_bytes += dp_packet_size(packet); |
0da3c61b | 4410 | ovs_mutex_unlock(&ofproto->stats_mutex); |
abe529af BP |
4411 | return error; |
4412 | } | |
0c4b9393 SH |
4413 | |
4414 | uint64_t | |
4415 | group_dpif_get_selection_method_param(const struct group_dpif *group) | |
4416 | { | |
4417 | return group->up.props.selection_method_param; | |
4418 | } | |
4419 | ||
4420 | const struct field_array * | |
4421 | group_dpif_get_fields(const struct group_dpif *group) | |
4422 | { | |
4423 | return &group->up.props.fields; | |
4424 | } | |
9583bc14 | 4425 | \f |
b5cbbcf6 AZ |
4426 | /* Return the version string of the datapath that backs up |
4427 | * this 'ofproto'. | |
4428 | */ | |
4429 | static const char * | |
4430 | get_datapath_version(const struct ofproto *ofproto_) | |
4431 | { | |
4432 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
4433 | ||
4434 | return ofproto->backer->dp_version_string; | |
4435 | } | |
4436 | ||
9583bc14 EJ |
4437 | static bool |
4438 | set_frag_handling(struct ofproto *ofproto_, | |
ad99e2ed | 4439 | enum ofputil_frag_handling frag_handling) |
abe529af BP |
4440 | { |
4441 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
ad99e2ed | 4442 | if (frag_handling != OFPUTIL_FRAG_REASM) { |
2cc3c58e | 4443 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
7257b535 BP |
4444 | return true; |
4445 | } else { | |
4446 | return false; | |
4447 | } | |
abe529af BP |
4448 | } |
4449 | ||
90bf1e07 | 4450 | static enum ofperr |
cf62fa4c | 4451 | packet_out(struct ofproto *ofproto_, struct dp_packet *packet, |
abe529af | 4452 | const struct flow *flow, |
f25d0cf3 | 4453 | const struct ofpact *ofpacts, size_t ofpacts_len) |
abe529af | 4454 | { |
419460f4 AW |
4455 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); |
4456 | ||
4457 | ofproto_dpif_execute_actions(ofproto, flow, NULL, ofpacts, | |
4458 | ofpacts_len, packet); | |
548de4dd | 4459 | return 0; |
abe529af | 4460 | } |
77ab5fd2 BP |
4461 | |
4462 | static enum ofperr | |
4463 | nxt_resume(struct ofproto *ofproto_, | |
4464 | const struct ofputil_packet_in_private *pin) | |
4465 | { | |
4466 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
4467 | ||
4468 | /* Translate pin into datapath actions. */ | |
4469 | uint64_t odp_actions_stub[1024 / 8]; | |
4470 | struct ofpbuf odp_actions = OFPBUF_STUB_INITIALIZER(odp_actions_stub); | |
4471 | enum slow_path_reason slow; | |
4472 | enum ofperr error = xlate_resume(ofproto, pin, &odp_actions, &slow); | |
4473 | ||
4474 | /* Steal 'pin->packet' and put it into a dp_packet. */ | |
4475 | struct dp_packet packet; | |
4476 | dp_packet_init(&packet, pin->public.packet_len); | |
4477 | dp_packet_put(&packet, pin->public.packet, pin->public.packet_len); | |
4478 | ||
1df7f7aa NS |
4479 | pkt_metadata_from_flow(&packet.md, &pin->public.flow_metadata.flow); |
4480 | ||
4481 | /* Fix up in_port. */ | |
4482 | ofproto_dpif_set_packet_odp_port(ofproto, | |
4483 | pin->public.flow_metadata.flow.in_port.ofp_port, | |
4484 | &packet); | |
4485 | ||
10b3f505 NS |
4486 | struct flow headers; |
4487 | flow_extract(&packet, &headers); | |
4488 | ||
77ab5fd2 BP |
4489 | /* Execute the datapath actions on the packet. */ |
4490 | struct dpif_execute execute = { | |
4491 | .actions = odp_actions.data, | |
4492 | .actions_len = odp_actions.size, | |
4493 | .needs_help = (slow & SLOW_ACTION) != 0, | |
4494 | .packet = &packet, | |
1cceb31b | 4495 | .flow = &headers, |
77ab5fd2 BP |
4496 | }; |
4497 | dpif_execute(ofproto->backer->dpif, &execute); | |
4498 | ||
4499 | /* Clean up. */ | |
4500 | ofpbuf_uninit(&odp_actions); | |
4501 | dp_packet_uninit(&packet); | |
4502 | ||
4503 | return error; | |
4504 | } | |
6fca1ffb BP |
4505 | \f |
4506 | /* NetFlow. */ | |
4507 | ||
4508 | static int | |
4509 | set_netflow(struct ofproto *ofproto_, | |
4510 | const struct netflow_options *netflow_options) | |
4511 | { | |
4512 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
4513 | ||
4514 | if (netflow_options) { | |
4515 | if (!ofproto->netflow) { | |
4516 | ofproto->netflow = netflow_create(); | |
7bab1576 | 4517 | ofproto->backer->need_revalidate = REV_RECONFIGURE; |
6fca1ffb BP |
4518 | } |
4519 | return netflow_set_options(ofproto->netflow, netflow_options); | |
7bab1576 EJ |
4520 | } else if (ofproto->netflow) { |
4521 | ofproto->backer->need_revalidate = REV_RECONFIGURE; | |
8e407f27 | 4522 | netflow_unref(ofproto->netflow); |
6fca1ffb | 4523 | ofproto->netflow = NULL; |
6fca1ffb | 4524 | } |
7bab1576 EJ |
4525 | |
4526 | return 0; | |
6fca1ffb | 4527 | } |
abe529af BP |
4528 | |
4529 | static void | |
4530 | get_netflow_ids(const struct ofproto *ofproto_, | |
4531 | uint8_t *engine_type, uint8_t *engine_id) | |
4532 | { | |
4533 | struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); | |
4534 | ||
acf60855 | 4535 | dpif_get_netflow_ids(ofproto->backer->dpif, engine_type, engine_id); |
abe529af BP |
4536 | } |
4537 | \f | |
4538 | static struct ofproto_dpif * | |
4539 | ofproto_dpif_lookup(const char *name) | |
4540 | { | |
b44a10b7 BP |
4541 | struct ofproto_dpif *ofproto; |
4542 | ||
4543 | HMAP_FOR_EACH_WITH_HASH (ofproto, all_ofproto_dpifs_node, | |
4544 | hash_string(name, 0), &all_ofproto_dpifs) { | |
4545 | if (!strcmp(ofproto->up.name, name)) { | |
4546 | return ofproto; | |
4547 | } | |
4548 | } | |
4549 | return NULL; | |
abe529af BP |
4550 | } |
4551 | ||
f0a3aa2e | 4552 | static void |
96e466a3 | 4553 | ofproto_unixctl_fdb_flush(struct unixctl_conn *conn, int argc, |
0e15264f | 4554 | const char *argv[], void *aux OVS_UNUSED) |
f0a3aa2e | 4555 | { |
490df1ef | 4556 | struct ofproto_dpif *ofproto; |
f0a3aa2e | 4557 | |
96e466a3 EJ |
4558 | if (argc > 1) { |
4559 | ofproto = ofproto_dpif_lookup(argv[1]); | |
4560 | if (!ofproto) { | |
bde9f75d | 4561 | unixctl_command_reply_error(conn, "no such bridge"); |
96e466a3 EJ |
4562 | return; |
4563 | } | |
509c0149 | 4564 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
30618594 | 4565 | mac_learning_flush(ofproto->ml); |
509c0149 | 4566 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
96e466a3 EJ |
4567 | } else { |
4568 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
509c0149 | 4569 | ovs_rwlock_wrlock(&ofproto->ml->rwlock); |
30618594 | 4570 | mac_learning_flush(ofproto->ml); |
509c0149 | 4571 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
96e466a3 | 4572 | } |
f0a3aa2e | 4573 | } |
f0a3aa2e | 4574 | |
bde9f75d | 4575 | unixctl_command_reply(conn, "table successfully flushed"); |
f0a3aa2e AA |
4576 | } |
4577 | ||
08fdcc12 FL |
4578 | static void |
4579 | ofproto_unixctl_mcast_snooping_flush(struct unixctl_conn *conn, int argc, | |
4580 | const char *argv[], void *aux OVS_UNUSED) | |
4581 | { | |
4582 | struct ofproto_dpif *ofproto; | |
4583 | ||
4584 | if (argc > 1) { | |
4585 | ofproto = ofproto_dpif_lookup(argv[1]); | |
4586 | if (!ofproto) { | |
4587 | unixctl_command_reply_error(conn, "no such bridge"); | |
4588 | return; | |
4589 | } | |
4590 | ||
4591 | if (!mcast_snooping_enabled(ofproto->ms)) { | |
4592 | unixctl_command_reply_error(conn, "multicast snooping is disabled"); | |
4593 | return; | |
4594 | } | |
4595 | mcast_snooping_mdb_flush(ofproto->ms); | |
4596 | } else { | |
4597 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
4598 | if (!mcast_snooping_enabled(ofproto->ms)) { | |
4599 | continue; | |
4600 | } | |
4601 | mcast_snooping_mdb_flush(ofproto->ms); | |
4602 | } | |
4603 | } | |
4604 | ||
4605 | unixctl_command_reply(conn, "table successfully flushed"); | |
4606 | } | |
4607 | ||
46c88433 EJ |
4608 | static struct ofport_dpif * |
4609 | ofbundle_get_a_port(const struct ofbundle *bundle) | |
4610 | { | |
417e7e66 | 4611 | return CONTAINER_OF(ovs_list_front(&bundle->ports), struct ofport_dpif, |
46c88433 EJ |
4612 | bundle_node); |
4613 | } | |
4614 | ||
abe529af | 4615 | static void |
0e15264f BP |
4616 | ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, |
4617 | const char *argv[], void *aux OVS_UNUSED) | |
abe529af BP |
4618 | { |
4619 | struct ds ds = DS_EMPTY_INITIALIZER; | |
4620 | const struct ofproto_dpif *ofproto; | |
4621 | const struct mac_entry *e; | |
4622 | ||
0e15264f | 4623 | ofproto = ofproto_dpif_lookup(argv[1]); |
abe529af | 4624 | if (!ofproto) { |
bde9f75d | 4625 | unixctl_command_reply_error(conn, "no such bridge"); |
abe529af BP |
4626 | return; |
4627 | } | |
4628 | ||
4629 | ds_put_cstr(&ds, " port VLAN MAC Age\n"); | |
509c0149 | 4630 | ovs_rwlock_rdlock(&ofproto->ml->rwlock); |
abe529af | 4631 | LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) { |
9d078ec2 | 4632 | struct ofbundle *bundle = mac_entry_get_port(ofproto->ml, e); |
ad28062f BP |
4633 | char name[OFP_MAX_PORT_NAME_LEN]; |
4634 | ||
4635 | ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, | |
4636 | name, sizeof name); | |
4637 | ds_put_format(&ds, "%5s %4d "ETH_ADDR_FMT" %3d\n", | |
4638 | name, e->vlan, ETH_ADDR_ARGS(e->mac), | |
e764773c | 4639 | mac_entry_age(ofproto->ml, e)); |
abe529af | 4640 | } |
509c0149 | 4641 | ovs_rwlock_unlock(&ofproto->ml->rwlock); |
bde9f75d | 4642 | unixctl_command_reply(conn, ds_cstr(&ds)); |
abe529af BP |
4643 | ds_destroy(&ds); |
4644 | } | |
4645 | ||
08fdcc12 FL |
4646 | static void |
4647 | ofproto_unixctl_mcast_snooping_show(struct unixctl_conn *conn, | |
4648 | int argc OVS_UNUSED, | |
4649 | const char *argv[], | |
4650 | void *aux OVS_UNUSED) | |
4651 | { | |
4652 | struct ds ds = DS_EMPTY_INITIALIZER; | |
4653 | const struct ofproto_dpif *ofproto; | |
4654 | const struct ofbundle *bundle; | |
4655 | const struct mcast_group *grp; | |
4656 | struct mcast_group_bundle *b; | |
4657 | struct mcast_mrouter_bundle *mrouter; | |
4658 | ||
4659 | ofproto = ofproto_dpif_lookup(argv[1]); | |
4660 | if (!ofproto) { | |
4661 | unixctl_command_reply_error(conn, "no such bridge"); | |
4662 | return; | |
4663 | } | |
4664 | ||
4665 | if (!mcast_snooping_enabled(ofproto->ms)) { | |
4666 | unixctl_command_reply_error(conn, "multicast snooping is disabled"); | |
4667 | return; | |
4668 | } | |
4669 | ||
4670 | ds_put_cstr(&ds, " port VLAN GROUP Age\n"); | |
4671 | ovs_rwlock_rdlock(&ofproto->ms->rwlock); | |
4672 | LIST_FOR_EACH (grp, group_node, &ofproto->ms->group_lru) { | |
4673 | LIST_FOR_EACH(b, bundle_node, &grp->bundle_lru) { | |
4674 | char name[OFP_MAX_PORT_NAME_LEN]; | |
4675 | ||
4676 | bundle = b->port; | |
4677 | ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, | |
4678 | name, sizeof name); | |
964a4d5f | 4679 | ds_put_format(&ds, "%5s %4d ", name, grp->vlan); |
ac6d120f | 4680 | ipv6_format_mapped(&grp->addr, &ds); |
964a4d5f | 4681 | ds_put_format(&ds, " %3d\n", |
08fdcc12 FL |
4682 | mcast_bundle_age(ofproto->ms, b)); |
4683 | } | |
4684 | } | |
4685 | ||
4686 | /* ports connected to multicast routers */ | |
4687 | LIST_FOR_EACH(mrouter, mrouter_node, &ofproto->ms->mrouter_lru) { | |
4688 | char name[OFP_MAX_PORT_NAME_LEN]; | |
4689 | ||
4690 | bundle = mrouter->port; | |
4691 | ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, | |
4692 | name, sizeof name); | |
c4bb1f8b | 4693 | ds_put_format(&ds, "%5s %4d querier %3d\n", |
08fdcc12 FL |
4694 | name, mrouter->vlan, |
4695 | mcast_mrouter_age(ofproto->ms, mrouter)); | |
4696 | } | |
4697 | ovs_rwlock_unlock(&ofproto->ms->rwlock); | |
4698 | unixctl_command_reply(conn, ds_cstr(&ds)); | |
4699 | ds_destroy(&ds); | |
4700 | } | |
4701 | ||
6a6455e5 | 4702 | struct trace_ctx { |
bbafd73b EJ |
4703 | struct xlate_out xout; |
4704 | struct xlate_in xin; | |
ce58df5b | 4705 | const struct flow *key; |
abe529af BP |
4706 | struct flow flow; |
4707 | struct ds *result; | |
1520ef4f BP |
4708 | struct flow_wildcards wc; |
4709 | struct ofpbuf odp_actions; | |
abe529af BP |
4710 | }; |
4711 | ||
4712 | static void | |
4d0acc70 | 4713 | trace_format_rule(struct ds *result, int level, const struct rule_dpif *rule) |
abe529af | 4714 | { |
dc723c44 | 4715 | const struct rule_actions *actions; |
15aaf599 BP |
4716 | ovs_be64 cookie; |
4717 | ||
abe529af BP |
4718 | ds_put_char_multiple(result, '\t', level); |
4719 | if (!rule) { | |
4720 | ds_put_cstr(result, "No match\n"); | |
4721 | return; | |
4722 | } | |
4723 | ||
15aaf599 BP |
4724 | ovs_mutex_lock(&rule->up.mutex); |
4725 | cookie = rule->up.flow_cookie; | |
4726 | ovs_mutex_unlock(&rule->up.mutex); | |
4727 | ||
29901626 | 4728 | ds_put_format(result, "Rule: table=%"PRIu8" cookie=%#"PRIx64" ", |
15aaf599 | 4729 | rule ? rule->up.table_id : 0, ntohll(cookie)); |
79feb7df | 4730 | cls_rule_format(&rule->up.cr, result); |
abe529af BP |
4731 | ds_put_char(result, '\n'); |
4732 | ||
15aaf599 BP |
4733 | actions = rule_dpif_get_actions(rule); |
4734 | ||
abe529af | 4735 | ds_put_char_multiple(result, '\t', level); |
455ecd77 | 4736 | ds_put_cstr(result, "OpenFlow actions="); |
15aaf599 | 4737 | ofpacts_format(actions->ofpacts, actions->ofpacts_len, result); |
abe529af BP |
4738 | ds_put_char(result, '\n'); |
4739 | } | |
4740 | ||
4741 | static void | |
4742 | trace_format_flow(struct ds *result, int level, const char *title, | |
bbafd73b | 4743 | struct trace_ctx *trace) |
abe529af BP |
4744 | { |
4745 | ds_put_char_multiple(result, '\t', level); | |
4746 | ds_put_format(result, "%s: ", title); | |
ce58df5b JR |
4747 | /* Do not report unchanged flows for resubmits. */ |
4748 | if ((level > 0 && flow_equal(&trace->xin.flow, &trace->flow)) | |
4749 | || (level == 0 && flow_equal(&trace->xin.flow, trace->key))) { | |
abe529af BP |
4750 | ds_put_cstr(result, "unchanged"); |
4751 | } else { | |
bbafd73b EJ |
4752 | flow_format(result, &trace->xin.flow); |
4753 | trace->flow = trace->xin.flow; | |
abe529af BP |
4754 | } |
4755 | ds_put_char(result, '\n'); | |
4756 | } | |
4757 | ||
eb9e1c26 EJ |
4758 | static void |
4759 | trace_format_regs(struct ds *result, int level, const char *title, | |
6a6455e5 | 4760 | struct trace_ctx *trace) |
eb9e1c26 EJ |
4761 | { |
4762 | size_t i; | |
4763 | ||
4764 | ds_put_char_multiple(result, '\t', level); | |
4765 | ds_put_format(result, "%s:", title); | |
4766 | for (i = 0; i < FLOW_N_REGS; i++) { | |
34582733 | 4767 | ds_put_format(result, " reg%"PRIuSIZE"=0x%"PRIx32, i, trace->flow.regs[i]); |
eb9e1c26 EJ |
4768 | } |
4769 | ds_put_char(result, '\n'); | |
4770 | } | |
4771 | ||
1ed8d352 EJ |
4772 | static void |
4773 | trace_format_odp(struct ds *result, int level, const char *title, | |
6a6455e5 | 4774 | struct trace_ctx *trace) |
1ed8d352 | 4775 | { |
1520ef4f | 4776 | struct ofpbuf *odp_actions = &trace->odp_actions; |
1ed8d352 EJ |
4777 | |
4778 | ds_put_char_multiple(result, '\t', level); | |
4779 | ds_put_format(result, "%s: ", title); | |
6fd6ed71 | 4780 | format_odp_actions(result, odp_actions->data, odp_actions->size); |
1ed8d352 EJ |
4781 | ds_put_char(result, '\n'); |
4782 | } | |
4783 | ||
41a91a0b AW |
4784 | static void |
4785 | trace_format_megaflow(struct ds *result, int level, const char *title, | |
4786 | struct trace_ctx *trace) | |
4787 | { | |
4788 | struct match match; | |
4789 | ||
4790 | ds_put_char_multiple(result, '\t', level); | |
4791 | ds_put_format(result, "%s: ", title); | |
1520ef4f | 4792 | match_init(&match, trace->key, &trace->wc); |
41a91a0b AW |
4793 | match_format(&match, result, OFP_DEFAULT_PRIORITY); |
4794 | ds_put_char(result, '\n'); | |
4795 | } | |
4796 | ||
9a9b001a | 4797 | static void trace_report(struct xlate_in *, int indentation, |
c1b3756c BP |
4798 | const char *format, ...) |
4799 | OVS_PRINTF_FORMAT(3, 4); | |
9a9b001a | 4800 | static void trace_report_valist(struct xlate_in *, int indentation, |
c1b3756c BP |
4801 | const char *format, va_list args) |
4802 | OVS_PRINTF_FORMAT(3, 0); | |
34dd0d78 | 4803 | |
abe529af | 4804 | static void |
9a9b001a | 4805 | trace_resubmit(struct xlate_in *xin, struct rule_dpif *rule, int indentation) |
abe529af | 4806 | { |
4d0acc70 | 4807 | struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin); |
abe529af BP |
4808 | struct ds *result = trace->result; |
4809 | ||
9a9b001a | 4810 | if (!indentation) { |
34dd0d78 | 4811 | if (rule == xin->ofproto->miss_rule) { |
9a9b001a | 4812 | trace_report(xin, indentation, |
c1b3756c | 4813 | "No match, flow generates \"packet in\"s."); |
34dd0d78 | 4814 | } else if (rule == xin->ofproto->no_packet_in_rule) { |
9a9b001a | 4815 | trace_report(xin, indentation, "No match, packets dropped because " |
c1b3756c | 4816 | "OFPPC_NO_PACKET_IN is set on in_port."); |
34dd0d78 | 4817 | } else if (rule == xin->ofproto->drop_frags_rule) { |
9a9b001a BP |
4818 | trace_report(xin, indentation, |
4819 | "Packets dropped because they are IP fragments and " | |
4820 | "the fragment handling mode is \"drop\"."); | |
34dd0d78 JR |
4821 | } |
4822 | } | |
4823 | ||
abe529af | 4824 | ds_put_char(result, '\n'); |
9a9b001a BP |
4825 | if (indentation) { |
4826 | trace_format_flow(result, indentation, "Resubmitted flow", trace); | |
4827 | trace_format_regs(result, indentation, "Resubmitted regs", trace); | |
4828 | trace_format_odp(result, indentation, "Resubmitted odp", trace); | |
4829 | trace_format_megaflow(result, indentation, "Resubmitted megaflow", | |
4830 | trace); | |
a8c31348 | 4831 | } |
9a9b001a | 4832 | trace_format_rule(result, indentation, rule); |
abe529af BP |
4833 | } |
4834 | ||
479df176 | 4835 | static void |
9a9b001a | 4836 | trace_report_valist(struct xlate_in *xin, int indentation, |
c1b3756c | 4837 | const char *format, va_list args) |
479df176 | 4838 | { |
4d0acc70 | 4839 | struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin); |
479df176 BP |
4840 | struct ds *result = trace->result; |
4841 | ||
9a9b001a | 4842 | ds_put_char_multiple(result, '\t', indentation); |
c1b3756c | 4843 | ds_put_format_valist(result, format, args); |
479df176 BP |
4844 | ds_put_char(result, '\n'); |
4845 | } | |
4846 | ||
c1b3756c | 4847 | static void |
9a9b001a | 4848 | trace_report(struct xlate_in *xin, int indentation, const char *format, ...) |
c1b3756c BP |
4849 | { |
4850 | va_list args; | |
4851 | ||
4852 | va_start(args, format); | |
9a9b001a | 4853 | trace_report_valist(xin, indentation, format, args); |
c1b3756c BP |
4854 | va_end(args); |
4855 | } | |
4856 | ||
b6f00895 BP |
4857 | /* Parses the 'argc' elements of 'argv', ignoring argv[0]. The following |
4858 | * forms are supported: | |
4859 | * | |
4860 | * - [dpname] odp_flow [-generate | packet] | |
4861 | * - bridge br_flow [-generate | packet] | |
4862 | * | |
4863 | * On success, initializes '*ofprotop' and 'flow' and returns NULL. On failure | |
316078c7 | 4864 | * returns a nonnull malloced error message. */ |
cab50449 | 4865 | static char * OVS_WARN_UNUSED_RESULT |
b6f00895 BP |
4866 | parse_flow_and_packet(int argc, const char *argv[], |
4867 | struct ofproto_dpif **ofprotop, struct flow *flow, | |
cf62fa4c | 4868 | struct dp_packet **packetp) |
abe529af | 4869 | { |
0a37839c | 4870 | const struct dpif_backer *backer = NULL; |
b6f00895 | 4871 | const char *error = NULL; |
316078c7 | 4872 | char *m_err = NULL; |
b6f00895 | 4873 | struct simap port_names = SIMAP_INITIALIZER(&port_names); |
cf62fa4c | 4874 | struct dp_packet *packet; |
b6f00895 BP |
4875 | struct ofpbuf odp_key; |
4876 | struct ofpbuf odp_mask; | |
abe529af | 4877 | |
50aa28fd | 4878 | ofpbuf_init(&odp_key, 0); |
ea5e3887 | 4879 | ofpbuf_init(&odp_mask, 0); |
abe529af | 4880 | |
50aa28fd AW |
4881 | /* Handle "-generate" or a hex string as the last argument. */ |
4882 | if (!strcmp(argv[argc - 1], "-generate")) { | |
cf62fa4c | 4883 | packet = dp_packet_new(0); |
50aa28fd AW |
4884 | argc--; |
4885 | } else { | |
b6f00895 | 4886 | error = eth_from_hex(argv[argc - 1], &packet); |
50aa28fd AW |
4887 | if (!error) { |
4888 | argc--; | |
4889 | } else if (argc == 4) { | |
4890 | /* The 3-argument form must end in "-generate' or a hex string. */ | |
50aa28fd AW |
4891 | goto exit; |
4892 | } | |
316078c7 | 4893 | error = NULL; |
e84173dc | 4894 | } |
876b0e1c | 4895 | |
0a37839c GS |
4896 | /* odp_flow can have its in_port specified as a name instead of port no. |
4897 | * We do not yet know whether a given flow is a odp_flow or a br_flow. | |
4898 | * But, to know whether a flow is odp_flow through odp_flow_from_string(), | |
4899 | * we need to create a simap of name to port no. */ | |
4900 | if (argc == 3) { | |
4901 | const char *dp_type; | |
4902 | if (!strncmp(argv[1], "ovs-", 4)) { | |
4903 | dp_type = argv[1] + 4; | |
4904 | } else { | |
4905 | dp_type = argv[1]; | |
4906 | } | |
4907 | backer = shash_find_data(&all_dpif_backers, dp_type); | |
b6f00895 | 4908 | } else if (argc == 2) { |
0a37839c GS |
4909 | struct shash_node *node; |
4910 | if (shash_count(&all_dpif_backers) == 1) { | |
4911 | node = shash_first(&all_dpif_backers); | |
4912 | backer = node->data; | |
4913 | } | |
b6f00895 BP |
4914 | } else { |
4915 | error = "Syntax error"; | |
4916 | goto exit; | |
0a37839c GS |
4917 | } |
4918 | if (backer && backer->dpif) { | |
4919 | struct dpif_port dpif_port; | |
4920 | struct dpif_port_dump port_dump; | |
4921 | DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, backer->dpif) { | |
4922 | simap_put(&port_names, dpif_port.name, | |
4923 | odp_to_u32(dpif_port.port_no)); | |
4924 | } | |
4925 | } | |
4926 | ||
50aa28fd AW |
4927 | /* Parse the flow and determine whether a datapath or |
4928 | * bridge is specified. If function odp_flow_key_from_string() | |
4929 | * returns 0, the flow is a odp_flow. If function | |
316078c7 | 4930 | * parse_ofp_exact_flow() returns NULL, the flow is a br_flow. */ |
b6f00895 BP |
4931 | if (!odp_flow_from_string(argv[argc - 1], &port_names, |
4932 | &odp_key, &odp_mask)) { | |
0a37839c | 4933 | if (!backer) { |
b6f00895 | 4934 | error = "Cannot find the datapath"; |
0a37839c | 4935 | goto exit; |
876b0e1c | 4936 | } |
8b3b8dd1 | 4937 | |
6fd6ed71 | 4938 | if (odp_flow_key_to_flow(odp_key.data, odp_key.size, flow) == ODP_FIT_ERROR) { |
5dd63cf5 | 4939 | error = "Failed to parse datapath flow key"; |
cc377352 EJ |
4940 | goto exit; |
4941 | } | |
4942 | ||
ef377a58 JR |
4943 | *ofprotop = xlate_lookup_ofproto(backer, flow, |
4944 | &flow->in_port.ofp_port); | |
4945 | if (*ofprotop == NULL) { | |
b6f00895 | 4946 | error = "Invalid datapath flow"; |
50aa28fd | 4947 | goto exit; |
8b3b8dd1 | 4948 | } |
316078c7 JR |
4949 | } else { |
4950 | char *err = parse_ofp_exact_flow(flow, NULL, argv[argc - 1], NULL); | |
876b0e1c | 4951 | |
316078c7 | 4952 | if (err) { |
5dd63cf5 | 4953 | m_err = xasprintf("Bad openflow flow syntax: %s", err); |
316078c7 | 4954 | free(err); |
50aa28fd | 4955 | goto exit; |
316078c7 JR |
4956 | } else { |
4957 | if (argc != 3) { | |
4958 | error = "Must specify bridge name"; | |
4959 | goto exit; | |
4960 | } | |
4961 | ||
4962 | *ofprotop = ofproto_dpif_lookup(argv[1]); | |
4963 | if (!*ofprotop) { | |
4964 | error = "Unknown bridge name"; | |
4965 | goto exit; | |
4966 | } | |
50aa28fd | 4967 | } |
abe529af BP |
4968 | } |
4969 | ||
50aa28fd AW |
4970 | /* Generate a packet, if requested. */ |
4971 | if (packet) { | |
cf62fa4c | 4972 | if (!dp_packet_size(packet)) { |
b6f00895 | 4973 | flow_compose(packet, flow); |
50aa28fd | 4974 | } else { |
50aa28fd AW |
4975 | /* Use the metadata from the flow and the packet argument |
4976 | * to reconstruct the flow. */ | |
cf62fa4c PS |
4977 | pkt_metadata_from_flow(&packet->md, flow); |
4978 | flow_extract(packet, flow); | |
50aa28fd AW |
4979 | } |
4980 | } | |
4981 | ||
6a6455e5 | 4982 | exit: |
316078c7 JR |
4983 | if (error && !m_err) { |
4984 | m_err = xstrdup(error); | |
4985 | } | |
4986 | if (m_err) { | |
cf62fa4c | 4987 | dp_packet_delete(packet); |
b6f00895 BP |
4988 | packet = NULL; |
4989 | } | |
4990 | *packetp = packet; | |
6a6455e5 | 4991 | ofpbuf_uninit(&odp_key); |
ea5e3887 | 4992 | ofpbuf_uninit(&odp_mask); |
0a37839c | 4993 | simap_destroy(&port_names); |
316078c7 | 4994 | return m_err; |
b6f00895 BP |
4995 | } |
4996 | ||
4997 | static void | |
4998 | ofproto_unixctl_trace(struct unixctl_conn *conn, int argc, const char *argv[], | |
4999 | void *aux OVS_UNUSED) | |
5000 | { | |
5001 | struct ofproto_dpif *ofproto; | |
cf62fa4c | 5002 | struct dp_packet *packet; |
316078c7 | 5003 | char *error; |
b6f00895 BP |
5004 | struct flow flow; |
5005 | ||
5006 | error = parse_flow_and_packet(argc, argv, &ofproto, &flow, &packet); | |
5007 | if (!error) { | |
5008 | struct ds result; | |
5009 | ||
5010 | ds_init(&result); | |
aee0979b | 5011 | ofproto_trace(ofproto, &flow, packet, NULL, 0, &result); |
b6f00895 BP |
5012 | unixctl_command_reply(conn, ds_cstr(&result)); |
5013 | ds_destroy(&result); | |
cf62fa4c | 5014 | dp_packet_delete(packet); |
b6f00895 BP |
5015 | } else { |
5016 | unixctl_command_reply_error(conn, error); | |
316078c7 | 5017 | free(error); |
b6f00895 | 5018 | } |
6a6455e5 EJ |
5019 | } |
5020 | ||
aee0979b BP |
5021 | static void |
5022 | ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc, | |
5023 | const char *argv[], void *aux OVS_UNUSED) | |
5024 | { | |
5025 | enum ofputil_protocol usable_protocols; | |
5026 | struct ofproto_dpif *ofproto; | |
5027 | bool enforce_consistency; | |
5028 | struct ofpbuf ofpacts; | |
cf62fa4c | 5029 | struct dp_packet *packet; |
aee0979b BP |
5030 | struct ds result; |
5031 | struct flow flow; | |
5032 | uint16_t in_port; | |
5033 | ||
5034 | /* Three kinds of error return values! */ | |
5035 | enum ofperr retval; | |
316078c7 | 5036 | char *error; |
aee0979b BP |
5037 | |
5038 | packet = NULL; | |
5039 | ds_init(&result); | |
5040 | ofpbuf_init(&ofpacts, 0); | |
5041 | ||
5042 | /* Parse actions. */ | |
c2d936a4 | 5043 | error = ofpacts_parse_actions(argv[--argc], &ofpacts, &usable_protocols); |
316078c7 JR |
5044 | if (error) { |
5045 | unixctl_command_reply_error(conn, error); | |
5046 | free(error); | |
aee0979b BP |
5047 | goto exit; |
5048 | } | |
5049 | ||
5050 | /* OpenFlow 1.1 and later suggest that the switch enforces certain forms of | |
ba2fe8e9 BP |
5051 | * consistency between the flow and the actions. With -consistent, we |
5052 | * enforce consistency even for a flow supported in OpenFlow 1.0. */ | |
aee0979b BP |
5053 | if (!strcmp(argv[1], "-consistent")) { |
5054 | enforce_consistency = true; | |
5055 | argv++; | |
5056 | argc--; | |
ba2fe8e9 BP |
5057 | } else { |
5058 | enforce_consistency = false; | |
aee0979b BP |
5059 | } |
5060 | ||
5061 | error = parse_flow_and_packet(argc, argv, &ofproto, &flow, &packet); | |
5062 | if (error) { | |
5063 | unixctl_command_reply_error(conn, error); | |
316078c7 | 5064 | free(error); |
aee0979b BP |
5065 | goto exit; |
5066 | } | |
5067 | ||
5068 | /* Do the same checks as handle_packet_out() in ofproto.c. | |
5069 | * | |
b8778a0d | 5070 | * We pass a 'table_id' of 0 to ofpacts_check(), which isn't |
aee0979b BP |
5071 | * strictly correct because these actions aren't in any table, but it's OK |
5072 | * because it 'table_id' is used only to check goto_table instructions, but | |
5073 | * packet-outs take a list of actions and therefore it can't include | |
5074 | * instructions. | |
5075 | * | |
5076 | * We skip the "meter" check here because meter is an instruction, not an | |
5077 | * action, and thus cannot appear in ofpacts. */ | |
5078 | in_port = ofp_to_u16(flow.in_port.ofp_port); | |
5079 | if (in_port >= ofproto->up.max_ports && in_port < ofp_to_u16(OFPP_MAX)) { | |
5080 | unixctl_command_reply_error(conn, "invalid in_port"); | |
5081 | goto exit; | |
5082 | } | |
ba2fe8e9 | 5083 | if (enforce_consistency) { |
89108874 JR |
5084 | retval = ofpacts_check_consistency(ofpacts.data, ofpacts.size, &flow, |
5085 | u16_to_ofp(ofproto->up.max_ports), | |
5086 | 0, ofproto->up.n_tables, | |
5087 | usable_protocols); | |
ba2fe8e9 | 5088 | } else { |
6fd6ed71 | 5089 | retval = ofpacts_check(ofpacts.data, ofpacts.size, &flow, |
89108874 JR |
5090 | u16_to_ofp(ofproto->up.max_ports), 0, |
5091 | ofproto->up.n_tables, &usable_protocols); | |
5092 | } | |
5093 | if (!retval) { | |
5094 | retval = ofproto_check_ofpacts(&ofproto->up, ofpacts.data, | |
5095 | ofpacts.size); | |
ba2fe8e9 BP |
5096 | } |
5097 | ||
aee0979b BP |
5098 | if (retval) { |
5099 | ds_clear(&result); | |
5100 | ds_put_format(&result, "Bad actions: %s", ofperr_to_string(retval)); | |
5101 | unixctl_command_reply_error(conn, ds_cstr(&result)); | |
5102 | goto exit; | |
5103 | } | |
5104 | ||
1f317cb5 | 5105 | ofproto_trace(ofproto, &flow, packet, |
6fd6ed71 | 5106 | ofpacts.data, ofpacts.size, &result); |
aee0979b BP |
5107 | unixctl_command_reply(conn, ds_cstr(&result)); |
5108 | ||
5109 | exit: | |
5110 | ds_destroy(&result); | |
cf62fa4c | 5111 | dp_packet_delete(packet); |
aee0979b BP |
5112 | ofpbuf_uninit(&ofpacts); |
5113 | } | |
5114 | ||
5115 | /* Implements a "trace" through 'ofproto''s flow table, appending a textual | |
5116 | * description of the results to 'ds'. | |
5117 | * | |
5118 | * The trace follows a packet with the specified 'flow' through the flow | |
5119 | * table. 'packet' may be nonnull to trace an actual packet, with consequent | |
5120 | * side effects (if it is nonnull then its flow must be 'flow'). | |
5121 | * | |
5122 | * If 'ofpacts' is nonnull then its 'ofpacts_len' bytes specify the actions to | |
5123 | * trace, otherwise the actions are determined by a flow table lookup. */ | |
ade6ad9c | 5124 | static void |
adcf00ba | 5125 | ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, |
cf62fa4c | 5126 | const struct dp_packet *packet, |
aee0979b BP |
5127 | const struct ofpact ofpacts[], size_t ofpacts_len, |
5128 | struct ds *ds) | |
6a6455e5 | 5129 | { |
41a91a0b | 5130 | struct trace_ctx trace; |
fff1b9c0 | 5131 | enum xlate_error error; |
6a6455e5 | 5132 | |
aee0979b | 5133 | ds_put_format(ds, "Bridge: %s\n", ofproto->up.name); |
6a6455e5 EJ |
5134 | ds_put_cstr(ds, "Flow: "); |
5135 | flow_format(ds, flow); | |
5136 | ds_put_char(ds, '\n'); | |
abe529af | 5137 | |
1520ef4f BP |
5138 | ofpbuf_init(&trace.odp_actions, 0); |
5139 | ||
a8c31348 BP |
5140 | trace.result = ds; |
5141 | trace.key = flow; /* Original flow key, used for megaflow. */ | |
5142 | trace.flow = *flow; /* May be modified by actions. */ | |
5143 | xlate_in_init(&trace.xin, ofproto, flow, flow->in_port.ofp_port, NULL, | |
1520ef4f BP |
5144 | ntohs(flow->tcp_flags), packet, &trace.wc, |
5145 | &trace.odp_actions); | |
a8c31348 BP |
5146 | trace.xin.ofpacts = ofpacts; |
5147 | trace.xin.ofpacts_len = ofpacts_len; | |
5148 | trace.xin.resubmit_hook = trace_resubmit; | |
c1b3756c | 5149 | trace.xin.report_hook = trace_report_valist; |
bcd2633a | 5150 | |
fff1b9c0 | 5151 | error = xlate_actions(&trace.xin, &trace.xout); |
a8c31348 | 5152 | ds_put_char(ds, '\n'); |
56de2148 | 5153 | trace.xin.flow.actset_output = 0; |
a8c31348 BP |
5154 | trace_format_flow(ds, 0, "Final flow", &trace); |
5155 | trace_format_megaflow(ds, 0, "Megaflow", &trace); | |
bcd2633a | 5156 | |
a8c31348 | 5157 | ds_put_cstr(ds, "Datapath actions: "); |
1520ef4f | 5158 | format_odp_actions(ds, trace.odp_actions.data, trace.odp_actions.size); |
876b0e1c | 5159 | |
fff1b9c0 JR |
5160 | if (error != XLATE_OK) { |
5161 | ds_put_format(ds, "\nTranslation failed (%s), packet is dropped.\n", | |
5162 | xlate_strerror(error)); | |
5163 | } else if (trace.xout.slow) { | |
a8c31348 | 5164 | enum slow_path_reason slow; |
04594cd5 | 5165 | |
a8c31348 BP |
5166 | ds_put_cstr(ds, "\nThis flow is handled by the userspace " |
5167 | "slow path because it:"); | |
04594cd5 | 5168 | |
a8c31348 BP |
5169 | slow = trace.xout.slow; |
5170 | while (slow) { | |
5171 | enum slow_path_reason bit = rightmost_1bit(slow); | |
04594cd5 | 5172 | |
a8c31348 BP |
5173 | ds_put_format(ds, "\n\t- %s.", |
5174 | slow_path_reason_to_explanation(bit)); | |
04594cd5 | 5175 | |
a8c31348 | 5176 | slow &= ~bit; |
876b0e1c | 5177 | } |
abe529af | 5178 | } |
a8c31348 BP |
5179 | |
5180 | xlate_out_uninit(&trace.xout); | |
1520ef4f | 5181 | ofpbuf_uninit(&trace.odp_actions); |
abe529af BP |
5182 | } |
5183 | ||
27022416 JP |
5184 | /* Store the current ofprotos in 'ofproto_shash'. Returns a sorted list |
5185 | * of the 'ofproto_shash' nodes. It is the responsibility of the caller | |
5186 | * to destroy 'ofproto_shash' and free the returned value. */ | |
5187 | static const struct shash_node ** | |
5188 | get_ofprotos(struct shash *ofproto_shash) | |
5189 | { | |
5190 | const struct ofproto_dpif *ofproto; | |
5191 | ||
5192 | HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { | |
5193 | char *name = xasprintf("%s@%s", ofproto->up.type, ofproto->up.name); | |
5194 | shash_add_nocopy(ofproto_shash, name, ofproto); | |
5195 | } | |
5196 | ||
5197 | return shash_sort(ofproto_shash); | |
5198 | } | |
5199 | ||
5200 | static void | |
5201 | ofproto_unixctl_dpif_dump_dps(struct unixctl_conn *conn, int argc OVS_UNUSED, | |
5202 | const char *argv[] OVS_UNUSED, | |
5203 | void *aux OVS_UNUSED) | |
5204 | { | |
5205 | struct ds ds = DS_EMPTY_INITIALIZER; | |
5206 | struct shash ofproto_shash; | |
5207 | const struct shash_node **sorted_ofprotos; | |
5208 | int i; | |
5209 | ||
5210 | shash_init(&ofproto_shash); | |
5211 | sorted_ofprotos = get_ofprotos(&ofproto_shash); | |
5212 | for (i = 0; i < shash_count(&ofproto_shash); i++) { | |
5213 | const struct shash_node *node = sorted_ofprotos[i]; | |
5214 | ds_put_format(&ds, "%s\n", node->name); | |
5215 | } | |
5216 | ||
5217 | shash_destroy(&ofproto_shash); | |
5218 | free(sorted_ofprotos); | |
5219 | ||
5220 | unixctl_command_reply(conn, ds_cstr(&ds)); | |
5221 | ds_destroy(&ds); | |
5222 | } | |
5223 | ||
dc54ef36 EJ |
5224 | static void |
5225 | dpif_show_backer(const struct dpif_backer *backer, struct ds *ds) | |
27022416 | 5226 | { |
dc54ef36 | 5227 | const struct shash_node **ofprotos; |
e79a6c83 | 5228 | struct dpif_dp_stats dp_stats; |
dc54ef36 | 5229 | struct shash ofproto_shash; |
09672174 | 5230 | size_t i; |
655ab909 | 5231 | |
e79a6c83 | 5232 | dpif_get_dp_stats(backer->dpif, &dp_stats); |
655ab909 | 5233 | |
dc54ef36 | 5234 | ds_put_format(ds, "%s: hit:%"PRIu64" missed:%"PRIu64"\n", |
e79a6c83 | 5235 | dpif_name(backer->dpif), dp_stats.n_hit, dp_stats.n_missed); |
dc54ef36 | 5236 | |
dc54ef36 EJ |
5237 | shash_init(&ofproto_shash); |
5238 | ofprotos = get_ofprotos(&ofproto_shash); | |
5239 | for (i = 0; i < shash_count(&ofproto_shash); i++) { | |
5240 | struct ofproto_dpif *ofproto = ofprotos[i]->data; | |
5241 | const struct shash_node **ports; | |
5242 | size_t j; | |
0a740f48 | 5243 | |
dc54ef36 EJ |
5244 | if (ofproto->backer != backer) { |
5245 | continue; | |
0a740f48 | 5246 | } |
27022416 | 5247 | |
e79a6c83 | 5248 | ds_put_format(ds, "\t%s:\n", ofproto->up.name); |
dc54ef36 EJ |
5249 | |
5250 | ports = shash_sort(&ofproto->up.port_by_name); | |
5251 | for (j = 0; j < shash_count(&ofproto->up.port_by_name); j++) { | |
5252 | const struct shash_node *node = ports[j]; | |
5253 | struct ofport *ofport = node->data; | |
5254 | struct smap config; | |
4e022ec0 | 5255 | odp_port_t odp_port; |
27022416 | 5256 | |
dc54ef36 EJ |
5257 | ds_put_format(ds, "\t\t%s %u/", netdev_get_name(ofport->netdev), |
5258 | ofport->ofp_port); | |
27022416 | 5259 | |
dc54ef36 | 5260 | odp_port = ofp_port_to_odp_port(ofproto, ofport->ofp_port); |
4e022ec0 | 5261 | if (odp_port != ODPP_NONE) { |
dc54ef36 EJ |
5262 | ds_put_format(ds, "%"PRIu32":", odp_port); |
5263 | } else { | |
5264 | ds_put_cstr(ds, "none:"); | |
5265 | } | |
27022416 | 5266 | |
dc54ef36 | 5267 | ds_put_format(ds, " (%s", netdev_get_type(ofport->netdev)); |
27022416 | 5268 | |
dc54ef36 EJ |
5269 | smap_init(&config); |
5270 | if (!netdev_get_config(ofport->netdev, &config)) { | |
5271 | const struct smap_node **nodes; | |
5272 | size_t i; | |
27022416 | 5273 | |
dc54ef36 EJ |
5274 | nodes = smap_sort(&config); |
5275 | for (i = 0; i < smap_count(&config); i++) { | |
5276 | const struct smap_node *node = nodes[i]; | |
5277 | ds_put_format(ds, "%c %s=%s", i ? ',' : ':', | |
5278 | node->key, node->value); | |
5279 | } | |
5280 | free(nodes); | |
27022416 | 5281 | } |
dc54ef36 EJ |
5282 | smap_destroy(&config); |
5283 | ||
27022416 | 5284 | ds_put_char(ds, ')'); |
dc54ef36 | 5285 | ds_put_char(ds, '\n'); |
27022416 | 5286 | } |
dc54ef36 | 5287 | free(ports); |
27022416 | 5288 | } |
dc54ef36 EJ |
5289 | shash_destroy(&ofproto_shash); |
5290 | free(ofprotos); | |
27022416 JP |
5291 | } |
5292 | ||
5293 | static void | |
dc54ef36 EJ |
5294 | ofproto_unixctl_dpif_show(struct unixctl_conn *conn, int argc OVS_UNUSED, |
5295 | const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED) | |
27022416 JP |
5296 | { |
5297 | struct ds ds = DS_EMPTY_INITIALIZER; | |
dc54ef36 EJ |
5298 | const struct shash_node **backers; |
5299 | int i; | |
27022416 | 5300 | |
dc54ef36 EJ |
5301 | backers = shash_sort(&all_dpif_backers); |
5302 | for (i = 0; i < shash_count(&all_dpif_backers); i++) { | |
5303 | dpif_show_backer(backers[i]->data, &ds); | |
27022416 | 5304 | } |
dc54ef36 | 5305 | free(backers); |
27022416 JP |
5306 | |
5307 | unixctl_command_reply(conn, ds_cstr(&ds)); | |
5308 | ds_destroy(&ds); | |
5309 | } | |
5310 | ||
5311 | static void | |
5312 | ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn, | |
5313 | int argc OVS_UNUSED, const char *argv[], | |
5314 | void *aux OVS_UNUSED) | |
5315 | { | |
27022416 | 5316 | const struct ofproto_dpif *ofproto; |
ac64794a BP |
5317 | |
5318 | struct ds ds = DS_EMPTY_INITIALIZER; | |
04b541df | 5319 | bool verbosity = false; |
ac64794a | 5320 | |
04b541df GS |
5321 | struct dpif_port dpif_port; |
5322 | struct dpif_port_dump port_dump; | |
5323 | struct hmap portno_names; | |
ac64794a BP |
5324 | |
5325 | struct dpif_flow_dump *flow_dump; | |
5326 | struct dpif_flow_dump_thread *flow_dump_thread; | |
5327 | struct dpif_flow f; | |
938eaa50 | 5328 | int error; |
27022416 | 5329 | |
04b541df | 5330 | ofproto = ofproto_dpif_lookup(argv[argc - 1]); |
27022416 JP |
5331 | if (!ofproto) { |
5332 | unixctl_command_reply_error(conn, "no such bridge"); | |
5333 | return; | |
5334 | } | |
5335 | ||
04b541df GS |
5336 | if (argc > 2 && !strcmp(argv[1], "-m")) { |
5337 | verbosity = true; | |
5338 | } | |
5339 | ||
5340 | hmap_init(&portno_names); | |
5341 | DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, ofproto->backer->dpif) { | |
5342 | odp_portno_names_set(&portno_names, dpif_port.port_no, dpif_port.name); | |
5343 | } | |
5344 | ||
1b849273 | 5345 | ds_init(&ds); |
64bb477f | 5346 | flow_dump = dpif_flow_dump_create(ofproto->backer->dpif, false); |
ac64794a BP |
5347 | flow_dump_thread = dpif_flow_dump_thread_create(flow_dump); |
5348 | while (dpif_flow_dump_next(flow_dump_thread, &f, 1)) { | |
ef377a58 JR |
5349 | struct flow flow; |
5350 | ||
5351 | if (odp_flow_key_to_flow(f.key, f.key_len, &flow) == ODP_FIT_ERROR | |
5352 | || xlate_lookup_ofproto(ofproto->backer, &flow, NULL) != ofproto) { | |
04d08d54 EJ |
5353 | continue; |
5354 | } | |
5355 | ||
70e5ed6f JS |
5356 | if (verbosity) { |
5357 | odp_format_ufid(&f.ufid, &ds); | |
5358 | ds_put_cstr(&ds, " "); | |
5359 | } | |
ac64794a BP |
5360 | odp_flow_format(f.key, f.key_len, f.mask, f.mask_len, |
5361 | &portno_names, &ds, verbosity); | |
1b849273 | 5362 | ds_put_cstr(&ds, ", "); |
ac64794a | 5363 | dpif_flow_stats_format(&f.stats, &ds); |
27022416 | 5364 | ds_put_cstr(&ds, ", actions:"); |
ac64794a | 5365 | format_odp_actions(&ds, f.actions, f.actions_len); |
27022416 JP |
5366 | ds_put_char(&ds, '\n'); |
5367 | } | |
ac64794a BP |
5368 | dpif_flow_dump_thread_destroy(flow_dump_thread); |
5369 | error = dpif_flow_dump_destroy(flow_dump); | |
27022416 | 5370 | |
938eaa50 | 5371 | if (error) { |
1b849273 JS |
5372 | ds_clear(&ds); |
5373 | ds_put_format(&ds, "dpif/dump_flows failed: %s", ovs_strerror(errno)); | |
5374 | unixctl_command_reply_error(conn, ds_cstr(&ds)); | |
5375 | } else { | |
5376 | unixctl_command_reply(conn, ds_cstr(&ds)); | |
5377 | } | |
04b541df GS |
5378 | odp_portno_names_destroy(&portno_names); |
5379 | hmap_destroy(&portno_names); | |
27022416 JP |
5380 | ds_destroy(&ds); |
5381 | } | |
5382 | ||
abe529af | 5383 | static void |
a36de779 PS |
5384 | ofproto_revalidate_all_backers(void) |
5385 | { | |
5386 | const struct shash_node **backers; | |
5387 | int i; | |
5388 | ||
5389 | backers = shash_sort(&all_dpif_backers); | |
5390 | for (i = 0; i < shash_count(&all_dpif_backers); i++) { | |
5391 | struct dpif_backer *backer = backers[i]->data; | |
5392 | backer->need_revalidate = REV_RECONFIGURE; | |
5393 | } | |
5394 | free(backers); | |
5395 | } | |
5396 | ||
5397 | static void | |
5398 | disable_tnl_push_pop(struct unixctl_conn *conn OVS_UNUSED, int argc OVS_UNUSED, | |
5399 | const char *argv[], void *aux OVS_UNUSED) | |
5400 | { | |
5401 | if (!strcasecmp(argv[1], "off")) { | |
5402 | ofproto_use_tnl_push_pop = false; | |
5403 | unixctl_command_reply(conn, "Tunnel push-pop off"); | |
5404 | ofproto_revalidate_all_backers(); | |
5405 | } else if (!strcasecmp(argv[1], "on")) { | |
5406 | ofproto_use_tnl_push_pop = true; | |
5407 | unixctl_command_reply(conn, "Tunnel push-pop on"); | |
5408 | ofproto_revalidate_all_backers(); | |
a6313b25 IM |
5409 | } else { |
5410 | unixctl_command_reply_error(conn, "Invalid argument"); | |
a36de779 PS |
5411 | } |
5412 | } | |
5413 | ||
aaca4fe0 WT |
5414 | static void |
5415 | disable_datapath_truncate(struct unixctl_conn *conn OVS_UNUSED, | |
5416 | int argc OVS_UNUSED, | |
5417 | const char *argv[] OVS_UNUSED, | |
5418 | void *aux OVS_UNUSED) | |
5419 | { | |
5420 | const struct shash_node **backers; | |
5421 | int i; | |
5422 | ||
5423 | backers = shash_sort(&all_dpif_backers); | |
5424 | for (i = 0; i < shash_count(&all_dpif_backers); i++) { | |
5425 | struct dpif_backer *backer = backers[i]->data; | |
5426 | backer->support.trunc = false; | |
5427 | } | |
5428 | free(backers); | |
5429 | unixctl_command_reply(conn, "Datapath truncate action diabled"); | |
5430 | } | |
5431 | ||
a36de779 PS |
5432 | static void |
5433 | ofproto_unixctl_init(void) | |
abe529af BP |
5434 | { |
5435 | static bool registered; | |
5436 | if (registered) { | |
5437 | return; | |
5438 | } | |
5439 | registered = true; | |
5440 | ||
0e15264f BP |
5441 | unixctl_command_register( |
5442 | "ofproto/trace", | |
dc8ce81f | 5443 | "{[dp_name] odp_flow | bridge br_flow} [-generate|packet]", |
50aa28fd | 5444 | 1, 3, ofproto_unixctl_trace, NULL); |
aee0979b BP |
5445 | unixctl_command_register( |
5446 | "ofproto/trace-packet-out", | |
5447 | "[-consistent] {[dp_name] odp_flow | bridge br_flow} [-generate|packet] actions", | |
5448 | 2, 6, ofproto_unixctl_trace_actions, NULL); | |
96e466a3 | 5449 | unixctl_command_register("fdb/flush", "[bridge]", 0, 1, |
0e15264f BP |
5450 | ofproto_unixctl_fdb_flush, NULL); |
5451 | unixctl_command_register("fdb/show", "bridge", 1, 1, | |
5452 | ofproto_unixctl_fdb_show, NULL); | |
08fdcc12 FL |
5453 | unixctl_command_register("mdb/flush", "[bridge]", 0, 1, |
5454 | ofproto_unixctl_mcast_snooping_flush, NULL); | |
5455 | unixctl_command_register("mdb/show", "bridge", 1, 1, | |
5456 | ofproto_unixctl_mcast_snooping_show, NULL); | |
27022416 JP |
5457 | unixctl_command_register("dpif/dump-dps", "", 0, 0, |
5458 | ofproto_unixctl_dpif_dump_dps, NULL); | |
dc54ef36 EJ |
5459 | unixctl_command_register("dpif/show", "", 0, 0, ofproto_unixctl_dpif_show, |
5460 | NULL); | |
04b541df | 5461 | unixctl_command_register("dpif/dump-flows", "[-m] bridge", 1, 2, |
27022416 | 5462 | ofproto_unixctl_dpif_dump_flows, NULL); |
a36de779 PS |
5463 | |
5464 | unixctl_command_register("ofproto/tnl-push-pop", "[on]|[off]", 1, 1, | |
5465 | disable_tnl_push_pop, NULL); | |
aaca4fe0 WT |
5466 | |
5467 | unixctl_command_register("dpif/disable-truncate", "", 0, 0, | |
5468 | disable_datapath_truncate, NULL); | |
abe529af | 5469 | } |
32260212 | 5470 | |
56c091ec SH |
5471 | /* Returns true if 'table' is the table used for internal rules, |
5472 | * false otherwise. */ | |
5473 | bool | |
5474 | table_is_internal(uint8_t table_id) | |
5475 | { | |
5476 | return table_id == TBL_INTERNAL; | |
5477 | } | |
abe529af | 5478 | \f |
e1b1d06a | 5479 | |
46c88433 | 5480 | static odp_port_t |
4e022ec0 | 5481 | ofp_port_to_odp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port) |
e1b1d06a | 5482 | { |
e672ff9b | 5483 | const struct ofport_dpif *ofport = ofp_port_to_ofport(ofproto, ofp_port); |
4e022ec0 | 5484 | return ofport ? ofport->odp_port : ODPP_NONE; |
e1b1d06a JP |
5485 | } |
5486 | ||
8449c4d6 | 5487 | struct ofport_dpif * |
4e022ec0 | 5488 | odp_port_to_ofport(const struct dpif_backer *backer, odp_port_t odp_port) |
e1b1d06a JP |
5489 | { |
5490 | struct ofport_dpif *port; | |
5491 | ||
8449c4d6 | 5492 | ovs_rwlock_rdlock(&backer->odp_to_ofport_lock); |
f9c0c3ec | 5493 | HMAP_FOR_EACH_IN_BUCKET (port, odp_port_node, hash_odp_port(odp_port), |
acf60855 | 5494 | &backer->odp_to_ofport_map) { |
e1b1d06a | 5495 | if (port->odp_port == odp_port) { |
8449c4d6 | 5496 | ovs_rwlock_unlock(&backer->odp_to_ofport_lock); |
acf60855 | 5497 | return port; |
e1b1d06a JP |
5498 | } |
5499 | } | |
5500 | ||
8449c4d6 | 5501 | ovs_rwlock_unlock(&backer->odp_to_ofport_lock); |
acf60855 JP |
5502 | return NULL; |
5503 | } | |
5504 | ||
4e022ec0 AW |
5505 | static ofp_port_t |
5506 | odp_port_to_ofp_port(const struct ofproto_dpif *ofproto, odp_port_t odp_port) | |
acf60855 JP |
5507 | { |
5508 | struct ofport_dpif *port; | |
5509 | ||
5510 | port = odp_port_to_ofport(ofproto->backer, odp_port); | |
6472ba11 | 5511 | if (port && &ofproto->up == port->up.ofproto) { |
acf60855 JP |
5512 | return port->up.ofp_port; |
5513 | } else { | |
5514 | return OFPP_NONE; | |
5515 | } | |
e1b1d06a | 5516 | } |
655ab909 | 5517 | |
adcf00ba AZ |
5518 | int |
5519 | ofproto_dpif_add_internal_flow(struct ofproto_dpif *ofproto, | |
fe99c360 | 5520 | const struct match *match, int priority, |
290ad78a | 5521 | uint16_t idle_timeout, |
adcf00ba AZ |
5522 | const struct ofpbuf *ofpacts, |
5523 | struct rule **rulep) | |
5524 | { | |
8be00367 | 5525 | struct ofproto_flow_mod ofm; |
adcf00ba AZ |
5526 | struct rule_dpif *rule; |
5527 | int error; | |
5528 | ||
39cc5c4a BP |
5529 | ofm.fm = (struct ofputil_flow_mod) { |
5530 | .match = *match, | |
5531 | .priority = priority, | |
5532 | .table_id = TBL_INTERNAL, | |
5533 | .command = OFPFC_ADD, | |
5534 | .idle_timeout = idle_timeout, | |
5535 | .flags = OFPUTIL_FF_HIDDEN_FIELDS | OFPUTIL_FF_NO_READONLY, | |
5536 | .ofpacts = ofpacts->data, | |
5537 | .ofpacts_len = ofpacts->size, | |
5538 | .delete_reason = OVS_OFPRR_NONE, | |
5539 | }; | |
8be00367 JR |
5540 | |
5541 | error = ofproto_flow_mod(&ofproto->up, &ofm); | |
adcf00ba AZ |
5542 | if (error) { |
5543 | VLOG_ERR_RL(&rl, "failed to add internal flow (%s)", | |
5544 | ofperr_to_string(error)); | |
5545 | *rulep = NULL; | |
5546 | return error; | |
5547 | } | |
5548 | ||
621b8064 JR |
5549 | rule = rule_dpif_lookup_in_table(ofproto, |
5550 | ofproto_dpif_get_tables_version(ofproto), | |
8be00367 | 5551 | TBL_INTERNAL, &ofm.fm.match.flow, |
1e1e1d19 | 5552 | &ofm.fm.match.wc); |
adcf00ba | 5553 | if (rule) { |
adcf00ba AZ |
5554 | *rulep = &rule->up; |
5555 | } else { | |
5556 | OVS_NOT_REACHED(); | |
5557 | } | |
5558 | return 0; | |
5559 | } | |
5560 | ||
5561 | int | |
5562 | ofproto_dpif_delete_internal_flow(struct ofproto_dpif *ofproto, | |
5563 | struct match *match, int priority) | |
5564 | { | |
8be00367 | 5565 | struct ofproto_flow_mod ofm; |
adcf00ba AZ |
5566 | int error; |
5567 | ||
39cc5c4a BP |
5568 | ofm.fm = (struct ofputil_flow_mod) { |
5569 | .match = *match, | |
5570 | .priority = priority, | |
5571 | .table_id = TBL_INTERNAL, | |
5572 | .flags = OFPUTIL_FF_HIDDEN_FIELDS | OFPUTIL_FF_NO_READONLY, | |
5573 | .command = OFPFC_DELETE_STRICT, | |
5574 | }; | |
8be00367 JR |
5575 | |
5576 | error = ofproto_flow_mod(&ofproto->up, &ofm); | |
adcf00ba AZ |
5577 | if (error) { |
5578 | VLOG_ERR_RL(&rl, "failed to delete internal flow (%s)", | |
5579 | ofperr_to_string(error)); | |
5580 | return error; | |
5581 | } | |
5582 | ||
5583 | return 0; | |
5584 | } | |
5585 | ||
290835f9 BP |
5586 | const struct uuid * |
5587 | ofproto_dpif_get_uuid(const struct ofproto_dpif *ofproto) | |
5588 | { | |
5589 | return &ofproto->uuid; | |
5590 | } | |
5591 | ||
abe529af | 5592 | const struct ofproto_class ofproto_dpif_class = { |
b0408fca | 5593 | init, |
abe529af BP |
5594 | enumerate_types, |
5595 | enumerate_names, | |
5596 | del, | |
0aeaabc8 | 5597 | port_open_type, |
acf60855 | 5598 | type_run, |
acf60855 | 5599 | type_wait, |
abe529af BP |
5600 | alloc, |
5601 | construct, | |
5602 | destruct, | |
5603 | dealloc, | |
5604 | run, | |
f07c97f5 | 5605 | ofproto_dpif_wait, |
e79a6c83 | 5606 | NULL, /* get_memory_usage. */ |
1c030aa5 | 5607 | type_get_memory_usage, |
abe529af | 5608 | flush, |
3c1bb396 | 5609 | query_tables, |
621b8064 | 5610 | set_tables_version, |
abe529af BP |
5611 | port_alloc, |
5612 | port_construct, | |
5613 | port_destruct, | |
5614 | port_dealloc, | |
5615 | port_modified, | |
5616 | port_reconfigured, | |
5617 | port_query_by_name, | |
5618 | port_add, | |
5619 | port_del, | |
91364d18 | 5620 | port_set_config, |
6527c598 | 5621 | port_get_stats, |
abe529af BP |
5622 | port_dump_start, |
5623 | port_dump_next, | |
5624 | port_dump_done, | |
5625 | port_poll, | |
5626 | port_poll_wait, | |
5627 | port_is_lacp_current, | |
50b9699f | 5628 | port_get_lacp_stats, |
0ab6decf | 5629 | NULL, /* rule_choose_table */ |
abe529af BP |
5630 | rule_alloc, |
5631 | rule_construct, | |
8037acb4 | 5632 | rule_insert, |
1fc71871 | 5633 | NULL, /* rule_delete */ |
abe529af BP |
5634 | rule_destruct, |
5635 | rule_dealloc, | |
abe529af BP |
5636 | rule_get_stats, |
5637 | rule_execute, | |
7257b535 | 5638 | set_frag_handling, |
abe529af | 5639 | packet_out, |
77ab5fd2 | 5640 | nxt_resume, |
abe529af BP |
5641 | set_netflow, |
5642 | get_netflow_ids, | |
5643 | set_sflow, | |
29089a54 | 5644 | set_ipfix, |
fb8f22c1 | 5645 | get_ipfix_stats, |
abe529af | 5646 | set_cfm, |
8f5514fe | 5647 | cfm_status_changed, |
9a9e3786 | 5648 | get_cfm_status, |
0477baa9 DF |
5649 | set_lldp, |
5650 | get_lldp_status, | |
5651 | set_aa, | |
5652 | aa_mapping_set, | |
5653 | aa_mapping_unset, | |
5654 | aa_vlan_get_queued, | |
5655 | aa_vlan_get_queue_size, | |
ccc09689 | 5656 | set_bfd, |
8f5514fe | 5657 | bfd_status_changed, |
ccc09689 | 5658 | get_bfd_status, |
21f7563c JP |
5659 | set_stp, |
5660 | get_stp_status, | |
5661 | set_stp_port, | |
5662 | get_stp_port_status, | |
fd28ce3a | 5663 | get_stp_port_stats, |
9efd308e DV |
5664 | set_rstp, |
5665 | get_rstp_status, | |
5666 | set_rstp_port, | |
5667 | get_rstp_port_status, | |
8b36f51e | 5668 | set_queues, |
abe529af BP |
5669 | bundle_set, |
5670 | bundle_remove, | |
ec7ceaed EJ |
5671 | mirror_set__, |
5672 | mirror_get_stats__, | |
abe529af BP |
5673 | set_flood_vlans, |
5674 | is_mirror_output_bundle, | |
8402c74b | 5675 | forward_bpdu_changed, |
c4069512 | 5676 | set_mac_table_config, |
7c38d0a5 FL |
5677 | set_mcast_snooping, |
5678 | set_mcast_snooping_port, | |
9cae45dc JR |
5679 | NULL, /* meter_get_features */ |
5680 | NULL, /* meter_set */ | |
5681 | NULL, /* meter_get */ | |
5682 | NULL, /* meter_del */ | |
00430a3f SH |
5683 | group_alloc, /* group_alloc */ |
5684 | group_construct, /* group_construct */ | |
5685 | group_destruct, /* group_destruct */ | |
5686 | group_dealloc, /* group_dealloc */ | |
5687 | group_modify, /* group_modify */ | |
5688 | group_get_stats, /* group_get_stats */ | |
b5cbbcf6 | 5689 | get_datapath_version, /* get_datapath_version */ |
abe529af | 5690 | }; |