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