diff options
Diffstat (limited to 'net/openvswitch/datapath.c')
-rw-r--r-- | net/openvswitch/datapath.c | 365 |
1 files changed, 213 insertions, 152 deletions
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 2e31d9e7f4dc..4e9a5f035cbc 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include "vport-netdev.h" | 59 | #include "vport-netdev.h" |
60 | 60 | ||
61 | int ovs_net_id __read_mostly; | 61 | int ovs_net_id __read_mostly; |
62 | EXPORT_SYMBOL_GPL(ovs_net_id); | ||
62 | 63 | ||
63 | static struct genl_family dp_packet_genl_family; | 64 | static struct genl_family dp_packet_genl_family; |
64 | static struct genl_family dp_flow_genl_family; | 65 | static struct genl_family dp_flow_genl_family; |
@@ -82,8 +83,7 @@ static bool ovs_must_notify(struct genl_family *family, struct genl_info *info, | |||
82 | unsigned int group) | 83 | unsigned int group) |
83 | { | 84 | { |
84 | return info->nlhdr->nlmsg_flags & NLM_F_ECHO || | 85 | return info->nlhdr->nlmsg_flags & NLM_F_ECHO || |
85 | genl_has_listeners(family, genl_info_net(info)->genl_sock, | 86 | genl_has_listeners(family, genl_info_net(info), group); |
86 | group); | ||
87 | } | 87 | } |
88 | 88 | ||
89 | static void ovs_notify(struct genl_family *family, | 89 | static void ovs_notify(struct genl_family *family, |
@@ -130,27 +130,41 @@ int lockdep_ovsl_is_held(void) | |||
130 | else | 130 | else |
131 | return 1; | 131 | return 1; |
132 | } | 132 | } |
133 | EXPORT_SYMBOL_GPL(lockdep_ovsl_is_held); | ||
133 | #endif | 134 | #endif |
134 | 135 | ||
135 | static struct vport *new_vport(const struct vport_parms *); | 136 | static struct vport *new_vport(const struct vport_parms *); |
136 | static int queue_gso_packets(struct datapath *dp, struct sk_buff *, | 137 | static int queue_gso_packets(struct datapath *dp, struct sk_buff *, |
138 | const struct sw_flow_key *, | ||
137 | const struct dp_upcall_info *); | 139 | const struct dp_upcall_info *); |
138 | static int queue_userspace_packet(struct datapath *dp, struct sk_buff *, | 140 | static int queue_userspace_packet(struct datapath *dp, struct sk_buff *, |
141 | const struct sw_flow_key *, | ||
139 | const struct dp_upcall_info *); | 142 | const struct dp_upcall_info *); |
140 | 143 | ||
141 | /* Must be called with rcu_read_lock or ovs_mutex. */ | 144 | /* Must be called with rcu_read_lock. */ |
142 | static struct datapath *get_dp(struct net *net, int dp_ifindex) | 145 | static struct datapath *get_dp_rcu(struct net *net, int dp_ifindex) |
143 | { | 146 | { |
144 | struct datapath *dp = NULL; | 147 | struct net_device *dev = dev_get_by_index_rcu(net, dp_ifindex); |
145 | struct net_device *dev; | ||
146 | 148 | ||
147 | rcu_read_lock(); | ||
148 | dev = dev_get_by_index_rcu(net, dp_ifindex); | ||
149 | if (dev) { | 149 | if (dev) { |
150 | struct vport *vport = ovs_internal_dev_get_vport(dev); | 150 | struct vport *vport = ovs_internal_dev_get_vport(dev); |
151 | if (vport) | 151 | if (vport) |
152 | dp = vport->dp; | 152 | return vport->dp; |
153 | } | 153 | } |
154 | |||
155 | return NULL; | ||
156 | } | ||
157 | |||
158 | /* The caller must hold either ovs_mutex or rcu_read_lock to keep the | ||
159 | * returned dp pointer valid. | ||
160 | */ | ||
161 | static inline struct datapath *get_dp(struct net *net, int dp_ifindex) | ||
162 | { | ||
163 | struct datapath *dp; | ||
164 | |||
165 | WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held()); | ||
166 | rcu_read_lock(); | ||
167 | dp = get_dp_rcu(net, dp_ifindex); | ||
154 | rcu_read_unlock(); | 168 | rcu_read_unlock(); |
155 | 169 | ||
156 | return dp; | 170 | return dp; |
@@ -163,7 +177,7 @@ const char *ovs_dp_name(const struct datapath *dp) | |||
163 | return vport->ops->get_name(vport); | 177 | return vport->ops->get_name(vport); |
164 | } | 178 | } |
165 | 179 | ||
166 | static int get_dpifindex(struct datapath *dp) | 180 | static int get_dpifindex(const struct datapath *dp) |
167 | { | 181 | { |
168 | struct vport *local; | 182 | struct vport *local; |
169 | int ifindex; | 183 | int ifindex; |
@@ -185,6 +199,7 @@ static void destroy_dp_rcu(struct rcu_head *rcu) | |||
185 | { | 199 | { |
186 | struct datapath *dp = container_of(rcu, struct datapath, rcu); | 200 | struct datapath *dp = container_of(rcu, struct datapath, rcu); |
187 | 201 | ||
202 | ovs_flow_tbl_destroy(&dp->table); | ||
188 | free_percpu(dp->stats_percpu); | 203 | free_percpu(dp->stats_percpu); |
189 | release_net(ovs_dp_get_net(dp)); | 204 | release_net(ovs_dp_get_net(dp)); |
190 | kfree(dp->ports); | 205 | kfree(dp->ports); |
@@ -243,6 +258,7 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key) | |||
243 | const struct vport *p = OVS_CB(skb)->input_vport; | 258 | const struct vport *p = OVS_CB(skb)->input_vport; |
244 | struct datapath *dp = p->dp; | 259 | struct datapath *dp = p->dp; |
245 | struct sw_flow *flow; | 260 | struct sw_flow *flow; |
261 | struct sw_flow_actions *sf_acts; | ||
246 | struct dp_stats_percpu *stats; | 262 | struct dp_stats_percpu *stats; |
247 | u64 *stats_counter; | 263 | u64 *stats_counter; |
248 | u32 n_mask_hit; | 264 | u32 n_mask_hit; |
@@ -256,10 +272,10 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key) | |||
256 | int error; | 272 | int error; |
257 | 273 | ||
258 | upcall.cmd = OVS_PACKET_CMD_MISS; | 274 | upcall.cmd = OVS_PACKET_CMD_MISS; |
259 | upcall.key = key; | ||
260 | upcall.userdata = NULL; | 275 | upcall.userdata = NULL; |
261 | upcall.portid = ovs_vport_find_upcall_portid(p, skb); | 276 | upcall.portid = ovs_vport_find_upcall_portid(p, skb); |
262 | error = ovs_dp_upcall(dp, skb, &upcall); | 277 | upcall.egress_tun_info = NULL; |
278 | error = ovs_dp_upcall(dp, skb, key, &upcall); | ||
263 | if (unlikely(error)) | 279 | if (unlikely(error)) |
264 | kfree_skb(skb); | 280 | kfree_skb(skb); |
265 | else | 281 | else |
@@ -268,10 +284,10 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key) | |||
268 | goto out; | 284 | goto out; |
269 | } | 285 | } |
270 | 286 | ||
271 | OVS_CB(skb)->flow = flow; | 287 | ovs_flow_stats_update(flow, key->tp.flags, skb); |
288 | sf_acts = rcu_dereference(flow->sf_acts); | ||
289 | ovs_execute_actions(dp, skb, sf_acts, key); | ||
272 | 290 | ||
273 | ovs_flow_stats_update(OVS_CB(skb)->flow, key->tp.flags, skb); | ||
274 | ovs_execute_actions(dp, skb, key); | ||
275 | stats_counter = &stats->n_hit; | 291 | stats_counter = &stats->n_hit; |
276 | 292 | ||
277 | out: | 293 | out: |
@@ -283,6 +299,7 @@ out: | |||
283 | } | 299 | } |
284 | 300 | ||
285 | int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, | 301 | int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, |
302 | const struct sw_flow_key *key, | ||
286 | const struct dp_upcall_info *upcall_info) | 303 | const struct dp_upcall_info *upcall_info) |
287 | { | 304 | { |
288 | struct dp_stats_percpu *stats; | 305 | struct dp_stats_percpu *stats; |
@@ -294,9 +311,9 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, | |||
294 | } | 311 | } |
295 | 312 | ||
296 | if (!skb_is_gso(skb)) | 313 | if (!skb_is_gso(skb)) |
297 | err = queue_userspace_packet(dp, skb, upcall_info); | 314 | err = queue_userspace_packet(dp, skb, key, upcall_info); |
298 | else | 315 | else |
299 | err = queue_gso_packets(dp, skb, upcall_info); | 316 | err = queue_gso_packets(dp, skb, key, upcall_info); |
300 | if (err) | 317 | if (err) |
301 | goto err; | 318 | goto err; |
302 | 319 | ||
@@ -313,37 +330,43 @@ err: | |||
313 | } | 330 | } |
314 | 331 | ||
315 | static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb, | 332 | static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb, |
333 | const struct sw_flow_key *key, | ||
316 | const struct dp_upcall_info *upcall_info) | 334 | const struct dp_upcall_info *upcall_info) |
317 | { | 335 | { |
318 | unsigned short gso_type = skb_shinfo(skb)->gso_type; | 336 | unsigned short gso_type = skb_shinfo(skb)->gso_type; |
319 | struct dp_upcall_info later_info; | ||
320 | struct sw_flow_key later_key; | 337 | struct sw_flow_key later_key; |
321 | struct sk_buff *segs, *nskb; | 338 | struct sk_buff *segs, *nskb; |
339 | struct ovs_skb_cb ovs_cb; | ||
322 | int err; | 340 | int err; |
323 | 341 | ||
342 | ovs_cb = *OVS_CB(skb); | ||
324 | segs = __skb_gso_segment(skb, NETIF_F_SG, false); | 343 | segs = __skb_gso_segment(skb, NETIF_F_SG, false); |
344 | *OVS_CB(skb) = ovs_cb; | ||
325 | if (IS_ERR(segs)) | 345 | if (IS_ERR(segs)) |
326 | return PTR_ERR(segs); | 346 | return PTR_ERR(segs); |
347 | if (segs == NULL) | ||
348 | return -EINVAL; | ||
349 | |||
350 | if (gso_type & SKB_GSO_UDP) { | ||
351 | /* The initial flow key extracted by ovs_flow_key_extract() | ||
352 | * in this case is for a first fragment, so we need to | ||
353 | * properly mark later fragments. | ||
354 | */ | ||
355 | later_key = *key; | ||
356 | later_key.ip.frag = OVS_FRAG_TYPE_LATER; | ||
357 | } | ||
327 | 358 | ||
328 | /* Queue all of the segments. */ | 359 | /* Queue all of the segments. */ |
329 | skb = segs; | 360 | skb = segs; |
330 | do { | 361 | do { |
331 | err = queue_userspace_packet(dp, skb, upcall_info); | 362 | *OVS_CB(skb) = ovs_cb; |
363 | if (gso_type & SKB_GSO_UDP && skb != segs) | ||
364 | key = &later_key; | ||
365 | |||
366 | err = queue_userspace_packet(dp, skb, key, upcall_info); | ||
332 | if (err) | 367 | if (err) |
333 | break; | 368 | break; |
334 | 369 | ||
335 | if (skb == segs && gso_type & SKB_GSO_UDP) { | ||
336 | /* The initial flow key extracted by ovs_flow_extract() | ||
337 | * in this case is for a first fragment, so we need to | ||
338 | * properly mark later fragments. | ||
339 | */ | ||
340 | later_key = *upcall_info->key; | ||
341 | later_key.ip.frag = OVS_FRAG_TYPE_LATER; | ||
342 | |||
343 | later_info = *upcall_info; | ||
344 | later_info.key = &later_key; | ||
345 | upcall_info = &later_info; | ||
346 | } | ||
347 | } while ((skb = skb->next)); | 370 | } while ((skb = skb->next)); |
348 | 371 | ||
349 | /* Free all of the segments. */ | 372 | /* Free all of the segments. */ |
@@ -358,46 +381,26 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb, | |||
358 | return err; | 381 | return err; |
359 | } | 382 | } |
360 | 383 | ||
361 | static size_t key_attr_size(void) | 384 | static size_t upcall_msg_size(const struct dp_upcall_info *upcall_info, |
362 | { | ||
363 | return nla_total_size(4) /* OVS_KEY_ATTR_PRIORITY */ | ||
364 | + nla_total_size(0) /* OVS_KEY_ATTR_TUNNEL */ | ||
365 | + nla_total_size(8) /* OVS_TUNNEL_KEY_ATTR_ID */ | ||
366 | + nla_total_size(4) /* OVS_TUNNEL_KEY_ATTR_IPV4_SRC */ | ||
367 | + nla_total_size(4) /* OVS_TUNNEL_KEY_ATTR_IPV4_DST */ | ||
368 | + nla_total_size(1) /* OVS_TUNNEL_KEY_ATTR_TOS */ | ||
369 | + nla_total_size(1) /* OVS_TUNNEL_KEY_ATTR_TTL */ | ||
370 | + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT */ | ||
371 | + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_CSUM */ | ||
372 | + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_OAM */ | ||
373 | + nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */ | ||
374 | + nla_total_size(4) /* OVS_KEY_ATTR_IN_PORT */ | ||
375 | + nla_total_size(4) /* OVS_KEY_ATTR_SKB_MARK */ | ||
376 | + nla_total_size(12) /* OVS_KEY_ATTR_ETHERNET */ | ||
377 | + nla_total_size(2) /* OVS_KEY_ATTR_ETHERTYPE */ | ||
378 | + nla_total_size(4) /* OVS_KEY_ATTR_8021Q */ | ||
379 | + nla_total_size(0) /* OVS_KEY_ATTR_ENCAP */ | ||
380 | + nla_total_size(2) /* OVS_KEY_ATTR_ETHERTYPE */ | ||
381 | + nla_total_size(40) /* OVS_KEY_ATTR_IPV6 */ | ||
382 | + nla_total_size(2) /* OVS_KEY_ATTR_ICMPV6 */ | ||
383 | + nla_total_size(28); /* OVS_KEY_ATTR_ND */ | ||
384 | } | ||
385 | |||
386 | static size_t upcall_msg_size(const struct nlattr *userdata, | ||
387 | unsigned int hdrlen) | 385 | unsigned int hdrlen) |
388 | { | 386 | { |
389 | size_t size = NLMSG_ALIGN(sizeof(struct ovs_header)) | 387 | size_t size = NLMSG_ALIGN(sizeof(struct ovs_header)) |
390 | + nla_total_size(hdrlen) /* OVS_PACKET_ATTR_PACKET */ | 388 | + nla_total_size(hdrlen) /* OVS_PACKET_ATTR_PACKET */ |
391 | + nla_total_size(key_attr_size()); /* OVS_PACKET_ATTR_KEY */ | 389 | + nla_total_size(ovs_key_attr_size()); /* OVS_PACKET_ATTR_KEY */ |
392 | 390 | ||
393 | /* OVS_PACKET_ATTR_USERDATA */ | 391 | /* OVS_PACKET_ATTR_USERDATA */ |
394 | if (userdata) | 392 | if (upcall_info->userdata) |
395 | size += NLA_ALIGN(userdata->nla_len); | 393 | size += NLA_ALIGN(upcall_info->userdata->nla_len); |
394 | |||
395 | /* OVS_PACKET_ATTR_EGRESS_TUN_KEY */ | ||
396 | if (upcall_info->egress_tun_info) | ||
397 | size += nla_total_size(ovs_tun_key_attr_size()); | ||
396 | 398 | ||
397 | return size; | 399 | return size; |
398 | } | 400 | } |
399 | 401 | ||
400 | static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, | 402 | static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, |
403 | const struct sw_flow_key *key, | ||
401 | const struct dp_upcall_info *upcall_info) | 404 | const struct dp_upcall_info *upcall_info) |
402 | { | 405 | { |
403 | struct ovs_header *upcall; | 406 | struct ovs_header *upcall; |
@@ -421,11 +424,10 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, | |||
421 | if (!nskb) | 424 | if (!nskb) |
422 | return -ENOMEM; | 425 | return -ENOMEM; |
423 | 426 | ||
424 | nskb = __vlan_put_tag(nskb, nskb->vlan_proto, vlan_tx_tag_get(nskb)); | 427 | nskb = __vlan_hwaccel_push_inside(nskb); |
425 | if (!nskb) | 428 | if (!nskb) |
426 | return -ENOMEM; | 429 | return -ENOMEM; |
427 | 430 | ||
428 | nskb->vlan_tci = 0; | ||
429 | skb = nskb; | 431 | skb = nskb; |
430 | } | 432 | } |
431 | 433 | ||
@@ -448,7 +450,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, | |||
448 | else | 450 | else |
449 | hlen = skb->len; | 451 | hlen = skb->len; |
450 | 452 | ||
451 | len = upcall_msg_size(upcall_info->userdata, hlen); | 453 | len = upcall_msg_size(upcall_info, hlen); |
452 | user_skb = genlmsg_new_unicast(len, &info, GFP_ATOMIC); | 454 | user_skb = genlmsg_new_unicast(len, &info, GFP_ATOMIC); |
453 | if (!user_skb) { | 455 | if (!user_skb) { |
454 | err = -ENOMEM; | 456 | err = -ENOMEM; |
@@ -460,7 +462,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, | |||
460 | upcall->dp_ifindex = dp_ifindex; | 462 | upcall->dp_ifindex = dp_ifindex; |
461 | 463 | ||
462 | nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_KEY); | 464 | nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_KEY); |
463 | err = ovs_nla_put_flow(upcall_info->key, upcall_info->key, user_skb); | 465 | err = ovs_nla_put_flow(key, key, user_skb); |
464 | BUG_ON(err); | 466 | BUG_ON(err); |
465 | nla_nest_end(user_skb, nla); | 467 | nla_nest_end(user_skb, nla); |
466 | 468 | ||
@@ -469,6 +471,14 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, | |||
469 | nla_len(upcall_info->userdata), | 471 | nla_len(upcall_info->userdata), |
470 | nla_data(upcall_info->userdata)); | 472 | nla_data(upcall_info->userdata)); |
471 | 473 | ||
474 | if (upcall_info->egress_tun_info) { | ||
475 | nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_EGRESS_TUN_KEY); | ||
476 | err = ovs_nla_put_egress_tunnel_key(user_skb, | ||
477 | upcall_info->egress_tun_info); | ||
478 | BUG_ON(err); | ||
479 | nla_nest_end(user_skb, nla); | ||
480 | } | ||
481 | |||
472 | /* Only reserve room for attribute header, packet data is added | 482 | /* Only reserve room for attribute header, packet data is added |
473 | * in skb_zerocopy() */ | 483 | * in skb_zerocopy() */ |
474 | if (!(nla = nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, 0))) { | 484 | if (!(nla = nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, 0))) { |
@@ -508,11 +518,13 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) | |||
508 | struct sw_flow_actions *acts; | 518 | struct sw_flow_actions *acts; |
509 | struct sk_buff *packet; | 519 | struct sk_buff *packet; |
510 | struct sw_flow *flow; | 520 | struct sw_flow *flow; |
521 | struct sw_flow_actions *sf_acts; | ||
511 | struct datapath *dp; | 522 | struct datapath *dp; |
512 | struct ethhdr *eth; | 523 | struct ethhdr *eth; |
513 | struct vport *input_vport; | 524 | struct vport *input_vport; |
514 | int len; | 525 | int len; |
515 | int err; | 526 | int err; |
527 | bool log = !a[OVS_FLOW_ATTR_PROBE]; | ||
516 | 528 | ||
517 | err = -EINVAL; | 529 | err = -EINVAL; |
518 | if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] || | 530 | if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] || |
@@ -546,29 +558,22 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) | |||
546 | goto err_kfree_skb; | 558 | goto err_kfree_skb; |
547 | 559 | ||
548 | err = ovs_flow_key_extract_userspace(a[OVS_PACKET_ATTR_KEY], packet, | 560 | err = ovs_flow_key_extract_userspace(a[OVS_PACKET_ATTR_KEY], packet, |
549 | &flow->key); | 561 | &flow->key, log); |
550 | if (err) | 562 | if (err) |
551 | goto err_flow_free; | 563 | goto err_flow_free; |
552 | 564 | ||
553 | acts = ovs_nla_alloc_flow_actions(nla_len(a[OVS_PACKET_ATTR_ACTIONS])); | ||
554 | err = PTR_ERR(acts); | ||
555 | if (IS_ERR(acts)) | ||
556 | goto err_flow_free; | ||
557 | |||
558 | err = ovs_nla_copy_actions(a[OVS_PACKET_ATTR_ACTIONS], | 565 | err = ovs_nla_copy_actions(a[OVS_PACKET_ATTR_ACTIONS], |
559 | &flow->key, 0, &acts); | 566 | &flow->key, &acts, log); |
560 | if (err) | 567 | if (err) |
561 | goto err_flow_free; | 568 | goto err_flow_free; |
562 | 569 | ||
563 | rcu_assign_pointer(flow->sf_acts, acts); | 570 | rcu_assign_pointer(flow->sf_acts, acts); |
564 | |||
565 | OVS_CB(packet)->egress_tun_info = NULL; | 571 | OVS_CB(packet)->egress_tun_info = NULL; |
566 | OVS_CB(packet)->flow = flow; | ||
567 | packet->priority = flow->key.phy.priority; | 572 | packet->priority = flow->key.phy.priority; |
568 | packet->mark = flow->key.phy.skb_mark; | 573 | packet->mark = flow->key.phy.skb_mark; |
569 | 574 | ||
570 | rcu_read_lock(); | 575 | rcu_read_lock(); |
571 | dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); | 576 | dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex); |
572 | err = -ENODEV; | 577 | err = -ENODEV; |
573 | if (!dp) | 578 | if (!dp) |
574 | goto err_unlock; | 579 | goto err_unlock; |
@@ -581,9 +586,10 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) | |||
581 | goto err_unlock; | 586 | goto err_unlock; |
582 | 587 | ||
583 | OVS_CB(packet)->input_vport = input_vport; | 588 | OVS_CB(packet)->input_vport = input_vport; |
589 | sf_acts = rcu_dereference(flow->sf_acts); | ||
584 | 590 | ||
585 | local_bh_disable(); | 591 | local_bh_disable(); |
586 | err = ovs_execute_actions(dp, packet, &flow->key); | 592 | err = ovs_execute_actions(dp, packet, sf_acts, &flow->key); |
587 | local_bh_enable(); | 593 | local_bh_enable(); |
588 | rcu_read_unlock(); | 594 | rcu_read_unlock(); |
589 | 595 | ||
@@ -626,7 +632,7 @@ static struct genl_family dp_packet_genl_family = { | |||
626 | .n_ops = ARRAY_SIZE(dp_packet_genl_ops), | 632 | .n_ops = ARRAY_SIZE(dp_packet_genl_ops), |
627 | }; | 633 | }; |
628 | 634 | ||
629 | static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats, | 635 | static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats, |
630 | struct ovs_dp_megaflow_stats *mega_stats) | 636 | struct ovs_dp_megaflow_stats *mega_stats) |
631 | { | 637 | { |
632 | int i; | 638 | int i; |
@@ -660,8 +666,8 @@ static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats, | |||
660 | static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts) | 666 | static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts) |
661 | { | 667 | { |
662 | return NLMSG_ALIGN(sizeof(struct ovs_header)) | 668 | return NLMSG_ALIGN(sizeof(struct ovs_header)) |
663 | + nla_total_size(key_attr_size()) /* OVS_FLOW_ATTR_KEY */ | 669 | + nla_total_size(ovs_key_attr_size()) /* OVS_FLOW_ATTR_KEY */ |
664 | + nla_total_size(key_attr_size()) /* OVS_FLOW_ATTR_MASK */ | 670 | + nla_total_size(ovs_key_attr_size()) /* OVS_FLOW_ATTR_MASK */ |
665 | + nla_total_size(sizeof(struct ovs_flow_stats)) /* OVS_FLOW_ATTR_STATS */ | 671 | + nla_total_size(sizeof(struct ovs_flow_stats)) /* OVS_FLOW_ATTR_STATS */ |
666 | + nla_total_size(1) /* OVS_FLOW_ATTR_TCP_FLAGS */ | 672 | + nla_total_size(1) /* OVS_FLOW_ATTR_TCP_FLAGS */ |
667 | + nla_total_size(8) /* OVS_FLOW_ATTR_USED */ | 673 | + nla_total_size(8) /* OVS_FLOW_ATTR_USED */ |
@@ -669,58 +675,67 @@ static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts) | |||
669 | } | 675 | } |
670 | 676 | ||
671 | /* Called with ovs_mutex or RCU read lock. */ | 677 | /* Called with ovs_mutex or RCU read lock. */ |
672 | static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex, | 678 | static int ovs_flow_cmd_fill_match(const struct sw_flow *flow, |
673 | struct sk_buff *skb, u32 portid, | 679 | struct sk_buff *skb) |
674 | u32 seq, u32 flags, u8 cmd) | ||
675 | { | 680 | { |
676 | const int skb_orig_len = skb->len; | ||
677 | struct nlattr *start; | ||
678 | struct ovs_flow_stats stats; | ||
679 | __be16 tcp_flags; | ||
680 | unsigned long used; | ||
681 | struct ovs_header *ovs_header; | ||
682 | struct nlattr *nla; | 681 | struct nlattr *nla; |
683 | int err; | 682 | int err; |
684 | 683 | ||
685 | ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family, flags, cmd); | ||
686 | if (!ovs_header) | ||
687 | return -EMSGSIZE; | ||
688 | |||
689 | ovs_header->dp_ifindex = dp_ifindex; | ||
690 | |||
691 | /* Fill flow key. */ | 684 | /* Fill flow key. */ |
692 | nla = nla_nest_start(skb, OVS_FLOW_ATTR_KEY); | 685 | nla = nla_nest_start(skb, OVS_FLOW_ATTR_KEY); |
693 | if (!nla) | 686 | if (!nla) |
694 | goto nla_put_failure; | 687 | return -EMSGSIZE; |
695 | 688 | ||
696 | err = ovs_nla_put_flow(&flow->unmasked_key, &flow->unmasked_key, skb); | 689 | err = ovs_nla_put_flow(&flow->unmasked_key, &flow->unmasked_key, skb); |
697 | if (err) | 690 | if (err) |
698 | goto error; | 691 | return err; |
692 | |||
699 | nla_nest_end(skb, nla); | 693 | nla_nest_end(skb, nla); |
700 | 694 | ||
695 | /* Fill flow mask. */ | ||
701 | nla = nla_nest_start(skb, OVS_FLOW_ATTR_MASK); | 696 | nla = nla_nest_start(skb, OVS_FLOW_ATTR_MASK); |
702 | if (!nla) | 697 | if (!nla) |
703 | goto nla_put_failure; | 698 | return -EMSGSIZE; |
704 | 699 | ||
705 | err = ovs_nla_put_flow(&flow->key, &flow->mask->key, skb); | 700 | err = ovs_nla_put_flow(&flow->key, &flow->mask->key, skb); |
706 | if (err) | 701 | if (err) |
707 | goto error; | 702 | return err; |
708 | 703 | ||
709 | nla_nest_end(skb, nla); | 704 | nla_nest_end(skb, nla); |
705 | return 0; | ||
706 | } | ||
707 | |||
708 | /* Called with ovs_mutex or RCU read lock. */ | ||
709 | static int ovs_flow_cmd_fill_stats(const struct sw_flow *flow, | ||
710 | struct sk_buff *skb) | ||
711 | { | ||
712 | struct ovs_flow_stats stats; | ||
713 | __be16 tcp_flags; | ||
714 | unsigned long used; | ||
710 | 715 | ||
711 | ovs_flow_stats_get(flow, &stats, &used, &tcp_flags); | 716 | ovs_flow_stats_get(flow, &stats, &used, &tcp_flags); |
712 | 717 | ||
713 | if (used && | 718 | if (used && |
714 | nla_put_u64(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used))) | 719 | nla_put_u64(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used))) |
715 | goto nla_put_failure; | 720 | return -EMSGSIZE; |
716 | 721 | ||
717 | if (stats.n_packets && | 722 | if (stats.n_packets && |
718 | nla_put(skb, OVS_FLOW_ATTR_STATS, sizeof(struct ovs_flow_stats), &stats)) | 723 | nla_put(skb, OVS_FLOW_ATTR_STATS, sizeof(struct ovs_flow_stats), &stats)) |
719 | goto nla_put_failure; | 724 | return -EMSGSIZE; |
720 | 725 | ||
721 | if ((u8)ntohs(tcp_flags) && | 726 | if ((u8)ntohs(tcp_flags) && |
722 | nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, (u8)ntohs(tcp_flags))) | 727 | nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, (u8)ntohs(tcp_flags))) |
723 | goto nla_put_failure; | 728 | return -EMSGSIZE; |
729 | |||
730 | return 0; | ||
731 | } | ||
732 | |||
733 | /* Called with ovs_mutex or RCU read lock. */ | ||
734 | static int ovs_flow_cmd_fill_actions(const struct sw_flow *flow, | ||
735 | struct sk_buff *skb, int skb_orig_len) | ||
736 | { | ||
737 | struct nlattr *start; | ||
738 | int err; | ||
724 | 739 | ||
725 | /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if | 740 | /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if |
726 | * this is the first flow to be dumped into 'skb'. This is unusual for | 741 | * this is the first flow to be dumped into 'skb'. This is unusual for |
@@ -744,17 +759,47 @@ static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex, | |||
744 | nla_nest_end(skb, start); | 759 | nla_nest_end(skb, start); |
745 | else { | 760 | else { |
746 | if (skb_orig_len) | 761 | if (skb_orig_len) |
747 | goto error; | 762 | return err; |
748 | 763 | ||
749 | nla_nest_cancel(skb, start); | 764 | nla_nest_cancel(skb, start); |
750 | } | 765 | } |
751 | } else if (skb_orig_len) | 766 | } else if (skb_orig_len) { |
752 | goto nla_put_failure; | 767 | return -EMSGSIZE; |
768 | } | ||
769 | |||
770 | return 0; | ||
771 | } | ||
772 | |||
773 | /* Called with ovs_mutex or RCU read lock. */ | ||
774 | static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex, | ||
775 | struct sk_buff *skb, u32 portid, | ||
776 | u32 seq, u32 flags, u8 cmd) | ||
777 | { | ||
778 | const int skb_orig_len = skb->len; | ||
779 | struct ovs_header *ovs_header; | ||
780 | int err; | ||
781 | |||
782 | ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family, | ||
783 | flags, cmd); | ||
784 | if (!ovs_header) | ||
785 | return -EMSGSIZE; | ||
786 | |||
787 | ovs_header->dp_ifindex = dp_ifindex; | ||
788 | |||
789 | err = ovs_flow_cmd_fill_match(flow, skb); | ||
790 | if (err) | ||
791 | goto error; | ||
792 | |||
793 | err = ovs_flow_cmd_fill_stats(flow, skb); | ||
794 | if (err) | ||
795 | goto error; | ||
796 | |||
797 | err = ovs_flow_cmd_fill_actions(flow, skb, skb_orig_len); | ||
798 | if (err) | ||
799 | goto error; | ||
753 | 800 | ||
754 | return genlmsg_end(skb, ovs_header); | 801 | return genlmsg_end(skb, ovs_header); |
755 | 802 | ||
756 | nla_put_failure: | ||
757 | err = -EMSGSIZE; | ||
758 | error: | 803 | error: |
759 | genlmsg_cancel(skb, ovs_header); | 804 | genlmsg_cancel(skb, ovs_header); |
760 | return err; | 805 | return err; |
@@ -809,13 +854,18 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info) | |||
809 | struct sw_flow_actions *acts; | 854 | struct sw_flow_actions *acts; |
810 | struct sw_flow_match match; | 855 | struct sw_flow_match match; |
811 | int error; | 856 | int error; |
857 | bool log = !a[OVS_FLOW_ATTR_PROBE]; | ||
812 | 858 | ||
813 | /* Must have key and actions. */ | 859 | /* Must have key and actions. */ |
814 | error = -EINVAL; | 860 | error = -EINVAL; |
815 | if (!a[OVS_FLOW_ATTR_KEY]) | 861 | if (!a[OVS_FLOW_ATTR_KEY]) { |
862 | OVS_NLERR(log, "Flow key attr not present in new flow."); | ||
816 | goto error; | 863 | goto error; |
817 | if (!a[OVS_FLOW_ATTR_ACTIONS]) | 864 | } |
865 | if (!a[OVS_FLOW_ATTR_ACTIONS]) { | ||
866 | OVS_NLERR(log, "Flow actions attr not present in new flow."); | ||
818 | goto error; | 867 | goto error; |
868 | } | ||
819 | 869 | ||
820 | /* Most of the time we need to allocate a new flow, do it before | 870 | /* Most of the time we need to allocate a new flow, do it before |
821 | * locking. | 871 | * locking. |
@@ -828,24 +878,19 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info) | |||
828 | 878 | ||
829 | /* Extract key. */ | 879 | /* Extract key. */ |
830 | ovs_match_init(&match, &new_flow->unmasked_key, &mask); | 880 | ovs_match_init(&match, &new_flow->unmasked_key, &mask); |
831 | error = ovs_nla_get_match(&match, | 881 | error = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], |
832 | a[OVS_FLOW_ATTR_KEY], a[OVS_FLOW_ATTR_MASK]); | 882 | a[OVS_FLOW_ATTR_MASK], log); |
833 | if (error) | 883 | if (error) |
834 | goto err_kfree_flow; | 884 | goto err_kfree_flow; |
835 | 885 | ||
836 | ovs_flow_mask_key(&new_flow->key, &new_flow->unmasked_key, &mask); | 886 | ovs_flow_mask_key(&new_flow->key, &new_flow->unmasked_key, &mask); |
837 | 887 | ||
838 | /* Validate actions. */ | 888 | /* Validate actions. */ |
839 | acts = ovs_nla_alloc_flow_actions(nla_len(a[OVS_FLOW_ATTR_ACTIONS])); | ||
840 | error = PTR_ERR(acts); | ||
841 | if (IS_ERR(acts)) | ||
842 | goto err_kfree_flow; | ||
843 | |||
844 | error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS], &new_flow->key, | 889 | error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS], &new_flow->key, |
845 | 0, &acts); | 890 | &acts, log); |
846 | if (error) { | 891 | if (error) { |
847 | OVS_NLERR("Flow actions may not be safe on all matching packets.\n"); | 892 | OVS_NLERR(log, "Flow actions may not be safe on all matching packets."); |
848 | goto err_kfree_acts; | 893 | goto err_kfree_flow; |
849 | } | 894 | } |
850 | 895 | ||
851 | reply = ovs_flow_cmd_alloc_info(acts, info, false); | 896 | reply = ovs_flow_cmd_alloc_info(acts, info, false); |
@@ -897,6 +942,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info) | |||
897 | } | 942 | } |
898 | /* The unmasked key has to be the same for flow updates. */ | 943 | /* The unmasked key has to be the same for flow updates. */ |
899 | if (unlikely(!ovs_flow_cmp_unmasked_key(flow, &match))) { | 944 | if (unlikely(!ovs_flow_cmp_unmasked_key(flow, &match))) { |
945 | /* Look for any overlapping flow. */ | ||
900 | flow = ovs_flow_tbl_lookup_exact(&dp->table, &match); | 946 | flow = ovs_flow_tbl_lookup_exact(&dp->table, &match); |
901 | if (!flow) { | 947 | if (!flow) { |
902 | error = -ENOENT; | 948 | error = -ENOENT; |
@@ -936,23 +982,21 @@ error: | |||
936 | return error; | 982 | return error; |
937 | } | 983 | } |
938 | 984 | ||
985 | /* Factor out action copy to avoid "Wframe-larger-than=1024" warning. */ | ||
939 | static struct sw_flow_actions *get_flow_actions(const struct nlattr *a, | 986 | static struct sw_flow_actions *get_flow_actions(const struct nlattr *a, |
940 | const struct sw_flow_key *key, | 987 | const struct sw_flow_key *key, |
941 | const struct sw_flow_mask *mask) | 988 | const struct sw_flow_mask *mask, |
989 | bool log) | ||
942 | { | 990 | { |
943 | struct sw_flow_actions *acts; | 991 | struct sw_flow_actions *acts; |
944 | struct sw_flow_key masked_key; | 992 | struct sw_flow_key masked_key; |
945 | int error; | 993 | int error; |
946 | 994 | ||
947 | acts = ovs_nla_alloc_flow_actions(nla_len(a)); | ||
948 | if (IS_ERR(acts)) | ||
949 | return acts; | ||
950 | |||
951 | ovs_flow_mask_key(&masked_key, key, mask); | 995 | ovs_flow_mask_key(&masked_key, key, mask); |
952 | error = ovs_nla_copy_actions(a, &masked_key, 0, &acts); | 996 | error = ovs_nla_copy_actions(a, &masked_key, &acts, log); |
953 | if (error) { | 997 | if (error) { |
954 | OVS_NLERR("Flow actions may not be safe on all matching packets.\n"); | 998 | OVS_NLERR(log, |
955 | kfree(acts); | 999 | "Actions may not be safe on all matching packets"); |
956 | return ERR_PTR(error); | 1000 | return ERR_PTR(error); |
957 | } | 1001 | } |
958 | 1002 | ||
@@ -971,29 +1015,31 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info) | |||
971 | struct sw_flow_actions *old_acts = NULL, *acts = NULL; | 1015 | struct sw_flow_actions *old_acts = NULL, *acts = NULL; |
972 | struct sw_flow_match match; | 1016 | struct sw_flow_match match; |
973 | int error; | 1017 | int error; |
1018 | bool log = !a[OVS_FLOW_ATTR_PROBE]; | ||
974 | 1019 | ||
975 | /* Extract key. */ | 1020 | /* Extract key. */ |
976 | error = -EINVAL; | 1021 | error = -EINVAL; |
977 | if (!a[OVS_FLOW_ATTR_KEY]) | 1022 | if (!a[OVS_FLOW_ATTR_KEY]) { |
1023 | OVS_NLERR(log, "Flow key attribute not present in set flow."); | ||
978 | goto error; | 1024 | goto error; |
1025 | } | ||
979 | 1026 | ||
980 | ovs_match_init(&match, &key, &mask); | 1027 | ovs_match_init(&match, &key, &mask); |
981 | error = ovs_nla_get_match(&match, | 1028 | error = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], |
982 | a[OVS_FLOW_ATTR_KEY], a[OVS_FLOW_ATTR_MASK]); | 1029 | a[OVS_FLOW_ATTR_MASK], log); |
983 | if (error) | 1030 | if (error) |
984 | goto error; | 1031 | goto error; |
985 | 1032 | ||
986 | /* Validate actions. */ | 1033 | /* Validate actions. */ |
987 | if (a[OVS_FLOW_ATTR_ACTIONS]) { | 1034 | if (a[OVS_FLOW_ATTR_ACTIONS]) { |
988 | acts = get_flow_actions(a[OVS_FLOW_ATTR_ACTIONS], &key, &mask); | 1035 | acts = get_flow_actions(a[OVS_FLOW_ATTR_ACTIONS], &key, &mask, |
1036 | log); | ||
989 | if (IS_ERR(acts)) { | 1037 | if (IS_ERR(acts)) { |
990 | error = PTR_ERR(acts); | 1038 | error = PTR_ERR(acts); |
991 | goto error; | 1039 | goto error; |
992 | } | 1040 | } |
993 | } | ||
994 | 1041 | ||
995 | /* Can allocate before locking if have acts. */ | 1042 | /* Can allocate before locking if have acts. */ |
996 | if (acts) { | ||
997 | reply = ovs_flow_cmd_alloc_info(acts, info, false); | 1043 | reply = ovs_flow_cmd_alloc_info(acts, info, false); |
998 | if (IS_ERR(reply)) { | 1044 | if (IS_ERR(reply)) { |
999 | error = PTR_ERR(reply); | 1045 | error = PTR_ERR(reply); |
@@ -1068,14 +1114,16 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info) | |||
1068 | struct datapath *dp; | 1114 | struct datapath *dp; |
1069 | struct sw_flow_match match; | 1115 | struct sw_flow_match match; |
1070 | int err; | 1116 | int err; |
1117 | bool log = !a[OVS_FLOW_ATTR_PROBE]; | ||
1071 | 1118 | ||
1072 | if (!a[OVS_FLOW_ATTR_KEY]) { | 1119 | if (!a[OVS_FLOW_ATTR_KEY]) { |
1073 | OVS_NLERR("Flow get message rejected, Key attribute missing.\n"); | 1120 | OVS_NLERR(log, |
1121 | "Flow get message rejected, Key attribute missing."); | ||
1074 | return -EINVAL; | 1122 | return -EINVAL; |
1075 | } | 1123 | } |
1076 | 1124 | ||
1077 | ovs_match_init(&match, &key, NULL); | 1125 | ovs_match_init(&match, &key, NULL); |
1078 | err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL); | 1126 | err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL, log); |
1079 | if (err) | 1127 | if (err) |
1080 | return err; | 1128 | return err; |
1081 | 1129 | ||
@@ -1116,10 +1164,12 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info) | |||
1116 | struct datapath *dp; | 1164 | struct datapath *dp; |
1117 | struct sw_flow_match match; | 1165 | struct sw_flow_match match; |
1118 | int err; | 1166 | int err; |
1167 | bool log = !a[OVS_FLOW_ATTR_PROBE]; | ||
1119 | 1168 | ||
1120 | if (likely(a[OVS_FLOW_ATTR_KEY])) { | 1169 | if (likely(a[OVS_FLOW_ATTR_KEY])) { |
1121 | ovs_match_init(&match, &key, NULL); | 1170 | ovs_match_init(&match, &key, NULL); |
1122 | err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL); | 1171 | err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL, |
1172 | log); | ||
1123 | if (unlikely(err)) | 1173 | if (unlikely(err)) |
1124 | return err; | 1174 | return err; |
1125 | } | 1175 | } |
@@ -1177,7 +1227,7 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1177 | struct datapath *dp; | 1227 | struct datapath *dp; |
1178 | 1228 | ||
1179 | rcu_read_lock(); | 1229 | rcu_read_lock(); |
1180 | dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); | 1230 | dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex); |
1181 | if (!dp) { | 1231 | if (!dp) { |
1182 | rcu_read_unlock(); | 1232 | rcu_read_unlock(); |
1183 | return -ENODEV; | 1233 | return -ENODEV; |
@@ -1209,8 +1259,10 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1209 | 1259 | ||
1210 | static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = { | 1260 | static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = { |
1211 | [OVS_FLOW_ATTR_KEY] = { .type = NLA_NESTED }, | 1261 | [OVS_FLOW_ATTR_KEY] = { .type = NLA_NESTED }, |
1262 | [OVS_FLOW_ATTR_MASK] = { .type = NLA_NESTED }, | ||
1212 | [OVS_FLOW_ATTR_ACTIONS] = { .type = NLA_NESTED }, | 1263 | [OVS_FLOW_ATTR_ACTIONS] = { .type = NLA_NESTED }, |
1213 | [OVS_FLOW_ATTR_CLEAR] = { .type = NLA_FLAG }, | 1264 | [OVS_FLOW_ATTR_CLEAR] = { .type = NLA_FLAG }, |
1265 | [OVS_FLOW_ATTR_PROBE] = { .type = NLA_FLAG }, | ||
1214 | }; | 1266 | }; |
1215 | 1267 | ||
1216 | static const struct genl_ops dp_flow_genl_ops[] = { | 1268 | static const struct genl_ops dp_flow_genl_ops[] = { |
@@ -1263,7 +1315,7 @@ static size_t ovs_dp_cmd_msg_size(void) | |||
1263 | return msgsize; | 1315 | return msgsize; |
1264 | } | 1316 | } |
1265 | 1317 | ||
1266 | /* Called with ovs_mutex or RCU read lock. */ | 1318 | /* Called with ovs_mutex. */ |
1267 | static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb, | 1319 | static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb, |
1268 | u32 portid, u32 seq, u32 flags, u8 cmd) | 1320 | u32 portid, u32 seq, u32 flags, u8 cmd) |
1269 | { | 1321 | { |
@@ -1311,7 +1363,7 @@ static struct sk_buff *ovs_dp_cmd_alloc_info(struct genl_info *info) | |||
1311 | 1363 | ||
1312 | /* Called with rcu_read_lock or ovs_mutex. */ | 1364 | /* Called with rcu_read_lock or ovs_mutex. */ |
1313 | static struct datapath *lookup_datapath(struct net *net, | 1365 | static struct datapath *lookup_datapath(struct net *net, |
1314 | struct ovs_header *ovs_header, | 1366 | const struct ovs_header *ovs_header, |
1315 | struct nlattr *a[OVS_DP_ATTR_MAX + 1]) | 1367 | struct nlattr *a[OVS_DP_ATTR_MAX + 1]) |
1316 | { | 1368 | { |
1317 | struct datapath *dp; | 1369 | struct datapath *dp; |
@@ -1339,7 +1391,7 @@ static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *in | |||
1339 | dp->user_features = 0; | 1391 | dp->user_features = 0; |
1340 | } | 1392 | } |
1341 | 1393 | ||
1342 | static void ovs_dp_change(struct datapath *dp, struct nlattr **a) | 1394 | static void ovs_dp_change(struct datapath *dp, struct nlattr *a[]) |
1343 | { | 1395 | { |
1344 | if (a[OVS_DP_ATTR_USER_FEATURES]) | 1396 | if (a[OVS_DP_ATTR_USER_FEATURES]) |
1345 | dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); | 1397 | dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); |
@@ -1440,7 +1492,7 @@ err_destroy_ports_array: | |||
1440 | err_destroy_percpu: | 1492 | err_destroy_percpu: |
1441 | free_percpu(dp->stats_percpu); | 1493 | free_percpu(dp->stats_percpu); |
1442 | err_destroy_table: | 1494 | err_destroy_table: |
1443 | ovs_flow_tbl_destroy(&dp->table, false); | 1495 | ovs_flow_tbl_destroy(&dp->table); |
1444 | err_free_dp: | 1496 | err_free_dp: |
1445 | release_net(ovs_dp_get_net(dp)); | 1497 | release_net(ovs_dp_get_net(dp)); |
1446 | kfree(dp); | 1498 | kfree(dp); |
@@ -1472,8 +1524,6 @@ static void __dp_destroy(struct datapath *dp) | |||
1472 | ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL)); | 1524 | ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL)); |
1473 | 1525 | ||
1474 | /* RCU destroy the flow table */ | 1526 | /* RCU destroy the flow table */ |
1475 | ovs_flow_tbl_destroy(&dp->table, true); | ||
1476 | |||
1477 | call_rcu(&dp->rcu, destroy_dp_rcu); | 1527 | call_rcu(&dp->rcu, destroy_dp_rcu); |
1478 | } | 1528 | } |
1479 | 1529 | ||
@@ -1553,7 +1603,7 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info) | |||
1553 | if (!reply) | 1603 | if (!reply) |
1554 | return -ENOMEM; | 1604 | return -ENOMEM; |
1555 | 1605 | ||
1556 | rcu_read_lock(); | 1606 | ovs_lock(); |
1557 | dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs); | 1607 | dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs); |
1558 | if (IS_ERR(dp)) { | 1608 | if (IS_ERR(dp)) { |
1559 | err = PTR_ERR(dp); | 1609 | err = PTR_ERR(dp); |
@@ -1562,12 +1612,12 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info) | |||
1562 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, | 1612 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, |
1563 | info->snd_seq, 0, OVS_DP_CMD_NEW); | 1613 | info->snd_seq, 0, OVS_DP_CMD_NEW); |
1564 | BUG_ON(err < 0); | 1614 | BUG_ON(err < 0); |
1565 | rcu_read_unlock(); | 1615 | ovs_unlock(); |
1566 | 1616 | ||
1567 | return genlmsg_reply(reply, info); | 1617 | return genlmsg_reply(reply, info); |
1568 | 1618 | ||
1569 | err_unlock_free: | 1619 | err_unlock_free: |
1570 | rcu_read_unlock(); | 1620 | ovs_unlock(); |
1571 | kfree_skb(reply); | 1621 | kfree_skb(reply); |
1572 | return err; | 1622 | return err; |
1573 | } | 1623 | } |
@@ -1579,8 +1629,8 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1579 | int skip = cb->args[0]; | 1629 | int skip = cb->args[0]; |
1580 | int i = 0; | 1630 | int i = 0; |
1581 | 1631 | ||
1582 | rcu_read_lock(); | 1632 | ovs_lock(); |
1583 | list_for_each_entry_rcu(dp, &ovs_net->dps, list_node) { | 1633 | list_for_each_entry(dp, &ovs_net->dps, list_node) { |
1584 | if (i >= skip && | 1634 | if (i >= skip && |
1585 | ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid, | 1635 | ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid, |
1586 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 1636 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
@@ -1588,7 +1638,7 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1588 | break; | 1638 | break; |
1589 | i++; | 1639 | i++; |
1590 | } | 1640 | } |
1591 | rcu_read_unlock(); | 1641 | ovs_unlock(); |
1592 | 1642 | ||
1593 | cb->args[0] = i; | 1643 | cb->args[0] = i; |
1594 | 1644 | ||
@@ -1705,7 +1755,7 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, u32 portid, | |||
1705 | 1755 | ||
1706 | /* Called with ovs_mutex or RCU read lock. */ | 1756 | /* Called with ovs_mutex or RCU read lock. */ |
1707 | static struct vport *lookup_vport(struct net *net, | 1757 | static struct vport *lookup_vport(struct net *net, |
1708 | struct ovs_header *ovs_header, | 1758 | const struct ovs_header *ovs_header, |
1709 | struct nlattr *a[OVS_VPORT_ATTR_MAX + 1]) | 1759 | struct nlattr *a[OVS_VPORT_ATTR_MAX + 1]) |
1710 | { | 1760 | { |
1711 | struct datapath *dp; | 1761 | struct datapath *dp; |
@@ -1762,6 +1812,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) | |||
1762 | return -ENOMEM; | 1812 | return -ENOMEM; |
1763 | 1813 | ||
1764 | ovs_lock(); | 1814 | ovs_lock(); |
1815 | restart: | ||
1765 | dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); | 1816 | dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); |
1766 | err = -ENODEV; | 1817 | err = -ENODEV; |
1767 | if (!dp) | 1818 | if (!dp) |
@@ -1793,8 +1844,11 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) | |||
1793 | 1844 | ||
1794 | vport = new_vport(&parms); | 1845 | vport = new_vport(&parms); |
1795 | err = PTR_ERR(vport); | 1846 | err = PTR_ERR(vport); |
1796 | if (IS_ERR(vport)) | 1847 | if (IS_ERR(vport)) { |
1848 | if (err == -EAGAIN) | ||
1849 | goto restart; | ||
1797 | goto exit_unlock_free; | 1850 | goto exit_unlock_free; |
1851 | } | ||
1798 | 1852 | ||
1799 | err = ovs_vport_cmd_fill_info(vport, reply, info->snd_portid, | 1853 | err = ovs_vport_cmd_fill_info(vport, reply, info->snd_portid, |
1800 | info->snd_seq, 0, OVS_VPORT_CMD_NEW); | 1854 | info->snd_seq, 0, OVS_VPORT_CMD_NEW); |
@@ -1937,7 +1991,7 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1937 | int i, j = 0; | 1991 | int i, j = 0; |
1938 | 1992 | ||
1939 | rcu_read_lock(); | 1993 | rcu_read_lock(); |
1940 | dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); | 1994 | dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex); |
1941 | if (!dp) { | 1995 | if (!dp) { |
1942 | rcu_read_unlock(); | 1996 | rcu_read_unlock(); |
1943 | return -ENODEV; | 1997 | return -ENODEV; |
@@ -2110,12 +2164,18 @@ static int __init dp_init(void) | |||
2110 | if (err) | 2164 | if (err) |
2111 | goto error_netns_exit; | 2165 | goto error_netns_exit; |
2112 | 2166 | ||
2167 | err = ovs_netdev_init(); | ||
2168 | if (err) | ||
2169 | goto error_unreg_notifier; | ||
2170 | |||
2113 | err = dp_register_genl(); | 2171 | err = dp_register_genl(); |
2114 | if (err < 0) | 2172 | if (err < 0) |
2115 | goto error_unreg_notifier; | 2173 | goto error_unreg_netdev; |
2116 | 2174 | ||
2117 | return 0; | 2175 | return 0; |
2118 | 2176 | ||
2177 | error_unreg_netdev: | ||
2178 | ovs_netdev_exit(); | ||
2119 | error_unreg_notifier: | 2179 | error_unreg_notifier: |
2120 | unregister_netdevice_notifier(&ovs_dp_device_notifier); | 2180 | unregister_netdevice_notifier(&ovs_dp_device_notifier); |
2121 | error_netns_exit: | 2181 | error_netns_exit: |
@@ -2135,6 +2195,7 @@ error: | |||
2135 | static void dp_cleanup(void) | 2195 | static void dp_cleanup(void) |
2136 | { | 2196 | { |
2137 | dp_unregister_genl(ARRAY_SIZE(dp_genl_families)); | 2197 | dp_unregister_genl(ARRAY_SIZE(dp_genl_families)); |
2198 | ovs_netdev_exit(); | ||
2138 | unregister_netdevice_notifier(&ovs_dp_device_notifier); | 2199 | unregister_netdevice_notifier(&ovs_dp_device_notifier); |
2139 | unregister_pernet_device(&ovs_net_ops); | 2200 | unregister_pernet_device(&ovs_net_ops); |
2140 | rcu_barrier(); | 2201 | rcu_barrier(); |