diff options
Diffstat (limited to 'net/openvswitch/datapath.c')
-rw-r--r-- | net/openvswitch/datapath.c | 261 |
1 files changed, 148 insertions, 113 deletions
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 6f5e1dd3be2d..8601b320b443 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c | |||
@@ -55,6 +55,7 @@ | |||
55 | 55 | ||
56 | #include "datapath.h" | 56 | #include "datapath.h" |
57 | #include "flow.h" | 57 | #include "flow.h" |
58 | #include "flow_table.h" | ||
58 | #include "flow_netlink.h" | 59 | #include "flow_netlink.h" |
59 | #include "vport-internal_dev.h" | 60 | #include "vport-internal_dev.h" |
60 | #include "vport-netdev.h" | 61 | #include "vport-netdev.h" |
@@ -108,10 +109,9 @@ int lockdep_ovsl_is_held(void) | |||
108 | #endif | 109 | #endif |
109 | 110 | ||
110 | static struct vport *new_vport(const struct vport_parms *); | 111 | static struct vport *new_vport(const struct vport_parms *); |
111 | static int queue_gso_packets(struct net *, int dp_ifindex, struct sk_buff *, | 112 | static int queue_gso_packets(struct datapath *dp, struct sk_buff *, |
112 | const struct dp_upcall_info *); | 113 | const struct dp_upcall_info *); |
113 | static int queue_userspace_packet(struct net *, int dp_ifindex, | 114 | static int queue_userspace_packet(struct datapath *dp, struct sk_buff *, |
114 | struct sk_buff *, | ||
115 | const struct dp_upcall_info *); | 115 | const struct dp_upcall_info *); |
116 | 116 | ||
117 | /* Must be called with rcu_read_lock or ovs_mutex. */ | 117 | /* Must be called with rcu_read_lock or ovs_mutex. */ |
@@ -133,7 +133,7 @@ static struct datapath *get_dp(struct net *net, int dp_ifindex) | |||
133 | } | 133 | } |
134 | 134 | ||
135 | /* Must be called with rcu_read_lock or ovs_mutex. */ | 135 | /* Must be called with rcu_read_lock or ovs_mutex. */ |
136 | const char *ovs_dp_name(const struct datapath *dp) | 136 | static const char *ovs_dp_name(const struct datapath *dp) |
137 | { | 137 | { |
138 | struct vport *vport = ovs_vport_ovsl_rcu(dp, OVSP_LOCAL); | 138 | struct vport *vport = ovs_vport_ovsl_rcu(dp, OVSP_LOCAL); |
139 | return vport->ops->get_name(vport); | 139 | return vport->ops->get_name(vport); |
@@ -161,7 +161,6 @@ static void destroy_dp_rcu(struct rcu_head *rcu) | |||
161 | { | 161 | { |
162 | struct datapath *dp = container_of(rcu, struct datapath, rcu); | 162 | struct datapath *dp = container_of(rcu, struct datapath, rcu); |
163 | 163 | ||
164 | ovs_flow_tbl_destroy(&dp->table); | ||
165 | free_percpu(dp->stats_percpu); | 164 | free_percpu(dp->stats_percpu); |
166 | release_net(ovs_dp_get_net(dp)); | 165 | release_net(ovs_dp_get_net(dp)); |
167 | kfree(dp->ports); | 166 | kfree(dp->ports); |
@@ -234,7 +233,7 @@ void ovs_dp_process_received_packet(struct vport *p, struct sk_buff *skb) | |||
234 | } | 233 | } |
235 | 234 | ||
236 | /* Look up flow. */ | 235 | /* Look up flow. */ |
237 | flow = ovs_flow_tbl_lookup(&dp->table, &key, &n_mask_hit); | 236 | flow = ovs_flow_tbl_lookup_stats(&dp->table, &key, &n_mask_hit); |
238 | if (unlikely(!flow)) { | 237 | if (unlikely(!flow)) { |
239 | struct dp_upcall_info upcall; | 238 | struct dp_upcall_info upcall; |
240 | 239 | ||
@@ -251,9 +250,9 @@ void ovs_dp_process_received_packet(struct vport *p, struct sk_buff *skb) | |||
251 | OVS_CB(skb)->flow = flow; | 250 | OVS_CB(skb)->flow = flow; |
252 | OVS_CB(skb)->pkt_key = &key; | 251 | OVS_CB(skb)->pkt_key = &key; |
253 | 252 | ||
254 | stats_counter = &stats->n_hit; | 253 | ovs_flow_stats_update(OVS_CB(skb)->flow, skb); |
255 | ovs_flow_used(OVS_CB(skb)->flow, skb); | ||
256 | ovs_execute_actions(dp, skb); | 254 | ovs_execute_actions(dp, skb); |
255 | stats_counter = &stats->n_hit; | ||
257 | 256 | ||
258 | out: | 257 | out: |
259 | /* Update datapath statistics. */ | 258 | /* Update datapath statistics. */ |
@@ -277,7 +276,6 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, | |||
277 | const struct dp_upcall_info *upcall_info) | 276 | const struct dp_upcall_info *upcall_info) |
278 | { | 277 | { |
279 | struct dp_stats_percpu *stats; | 278 | struct dp_stats_percpu *stats; |
280 | int dp_ifindex; | ||
281 | int err; | 279 | int err; |
282 | 280 | ||
283 | if (upcall_info->portid == 0) { | 281 | if (upcall_info->portid == 0) { |
@@ -285,16 +283,10 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, | |||
285 | goto err; | 283 | goto err; |
286 | } | 284 | } |
287 | 285 | ||
288 | dp_ifindex = get_dpifindex(dp); | ||
289 | if (!dp_ifindex) { | ||
290 | err = -ENODEV; | ||
291 | goto err; | ||
292 | } | ||
293 | |||
294 | if (!skb_is_gso(skb)) | 286 | if (!skb_is_gso(skb)) |
295 | err = queue_userspace_packet(ovs_dp_get_net(dp), dp_ifindex, skb, upcall_info); | 287 | err = queue_userspace_packet(dp, skb, upcall_info); |
296 | else | 288 | else |
297 | err = queue_gso_packets(ovs_dp_get_net(dp), dp_ifindex, skb, upcall_info); | 289 | err = queue_gso_packets(dp, skb, upcall_info); |
298 | if (err) | 290 | if (err) |
299 | goto err; | 291 | goto err; |
300 | 292 | ||
@@ -310,8 +302,7 @@ err: | |||
310 | return err; | 302 | return err; |
311 | } | 303 | } |
312 | 304 | ||
313 | static int queue_gso_packets(struct net *net, int dp_ifindex, | 305 | static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb, |
314 | struct sk_buff *skb, | ||
315 | const struct dp_upcall_info *upcall_info) | 306 | const struct dp_upcall_info *upcall_info) |
316 | { | 307 | { |
317 | unsigned short gso_type = skb_shinfo(skb)->gso_type; | 308 | unsigned short gso_type = skb_shinfo(skb)->gso_type; |
@@ -320,14 +311,14 @@ static int queue_gso_packets(struct net *net, int dp_ifindex, | |||
320 | struct sk_buff *segs, *nskb; | 311 | struct sk_buff *segs, *nskb; |
321 | int err; | 312 | int err; |
322 | 313 | ||
323 | segs = __skb_gso_segment(skb, NETIF_F_SG | NETIF_F_HW_CSUM, false); | 314 | segs = __skb_gso_segment(skb, NETIF_F_SG, false); |
324 | if (IS_ERR(segs)) | 315 | if (IS_ERR(segs)) |
325 | return PTR_ERR(segs); | 316 | return PTR_ERR(segs); |
326 | 317 | ||
327 | /* Queue all of the segments. */ | 318 | /* Queue all of the segments. */ |
328 | skb = segs; | 319 | skb = segs; |
329 | do { | 320 | do { |
330 | err = queue_userspace_packet(net, dp_ifindex, skb, upcall_info); | 321 | err = queue_userspace_packet(dp, skb, upcall_info); |
331 | if (err) | 322 | if (err) |
332 | break; | 323 | break; |
333 | 324 | ||
@@ -380,11 +371,11 @@ static size_t key_attr_size(void) | |||
380 | + nla_total_size(28); /* OVS_KEY_ATTR_ND */ | 371 | + nla_total_size(28); /* OVS_KEY_ATTR_ND */ |
381 | } | 372 | } |
382 | 373 | ||
383 | static size_t upcall_msg_size(const struct sk_buff *skb, | 374 | static size_t upcall_msg_size(const struct nlattr *userdata, |
384 | const struct nlattr *userdata) | 375 | unsigned int hdrlen) |
385 | { | 376 | { |
386 | size_t size = NLMSG_ALIGN(sizeof(struct ovs_header)) | 377 | size_t size = NLMSG_ALIGN(sizeof(struct ovs_header)) |
387 | + nla_total_size(skb->len) /* OVS_PACKET_ATTR_PACKET */ | 378 | + nla_total_size(hdrlen) /* OVS_PACKET_ATTR_PACKET */ |
388 | + nla_total_size(key_attr_size()); /* OVS_PACKET_ATTR_KEY */ | 379 | + nla_total_size(key_attr_size()); /* OVS_PACKET_ATTR_KEY */ |
389 | 380 | ||
390 | /* OVS_PACKET_ATTR_USERDATA */ | 381 | /* OVS_PACKET_ATTR_USERDATA */ |
@@ -394,15 +385,24 @@ static size_t upcall_msg_size(const struct sk_buff *skb, | |||
394 | return size; | 385 | return size; |
395 | } | 386 | } |
396 | 387 | ||
397 | static int queue_userspace_packet(struct net *net, int dp_ifindex, | 388 | static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, |
398 | struct sk_buff *skb, | ||
399 | const struct dp_upcall_info *upcall_info) | 389 | const struct dp_upcall_info *upcall_info) |
400 | { | 390 | { |
401 | struct ovs_header *upcall; | 391 | struct ovs_header *upcall; |
402 | struct sk_buff *nskb = NULL; | 392 | struct sk_buff *nskb = NULL; |
403 | struct sk_buff *user_skb; /* to be queued to userspace */ | 393 | struct sk_buff *user_skb; /* to be queued to userspace */ |
404 | struct nlattr *nla; | 394 | struct nlattr *nla; |
405 | int err; | 395 | struct genl_info info = { |
396 | .dst_sk = ovs_dp_get_net(dp)->genl_sock, | ||
397 | .snd_portid = upcall_info->portid, | ||
398 | }; | ||
399 | size_t len; | ||
400 | unsigned int hlen; | ||
401 | int err, dp_ifindex; | ||
402 | |||
403 | dp_ifindex = get_dpifindex(dp); | ||
404 | if (!dp_ifindex) | ||
405 | return -ENODEV; | ||
406 | 406 | ||
407 | if (vlan_tx_tag_present(skb)) { | 407 | if (vlan_tx_tag_present(skb)) { |
408 | nskb = skb_clone(skb, GFP_ATOMIC); | 408 | nskb = skb_clone(skb, GFP_ATOMIC); |
@@ -422,7 +422,22 @@ static int queue_userspace_packet(struct net *net, int dp_ifindex, | |||
422 | goto out; | 422 | goto out; |
423 | } | 423 | } |
424 | 424 | ||
425 | user_skb = genlmsg_new(upcall_msg_size(skb, upcall_info->userdata), GFP_ATOMIC); | 425 | /* Complete checksum if needed */ |
426 | if (skb->ip_summed == CHECKSUM_PARTIAL && | ||
427 | (err = skb_checksum_help(skb))) | ||
428 | goto out; | ||
429 | |||
430 | /* Older versions of OVS user space enforce alignment of the last | ||
431 | * Netlink attribute to NLA_ALIGNTO which would require extensive | ||
432 | * padding logic. Only perform zerocopy if padding is not required. | ||
433 | */ | ||
434 | if (dp->user_features & OVS_DP_F_UNALIGNED) | ||
435 | hlen = skb_zerocopy_headlen(skb); | ||
436 | else | ||
437 | hlen = skb->len; | ||
438 | |||
439 | len = upcall_msg_size(upcall_info->userdata, hlen); | ||
440 | user_skb = genlmsg_new_unicast(len, &info, GFP_ATOMIC); | ||
426 | if (!user_skb) { | 441 | if (!user_skb) { |
427 | err = -ENOMEM; | 442 | err = -ENOMEM; |
428 | goto out; | 443 | goto out; |
@@ -441,26 +456,32 @@ static int queue_userspace_packet(struct net *net, int dp_ifindex, | |||
441 | nla_len(upcall_info->userdata), | 456 | nla_len(upcall_info->userdata), |
442 | nla_data(upcall_info->userdata)); | 457 | nla_data(upcall_info->userdata)); |
443 | 458 | ||
444 | nla = __nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, skb->len); | 459 | /* Only reserve room for attribute header, packet data is added |
460 | * in skb_zerocopy() */ | ||
461 | if (!(nla = nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, 0))) { | ||
462 | err = -ENOBUFS; | ||
463 | goto out; | ||
464 | } | ||
465 | nla->nla_len = nla_attr_size(skb->len); | ||
466 | |||
467 | skb_zerocopy(user_skb, skb, skb->len, hlen); | ||
468 | |||
469 | /* Pad OVS_PACKET_ATTR_PACKET if linear copy was performed */ | ||
470 | if (!(dp->user_features & OVS_DP_F_UNALIGNED)) { | ||
471 | size_t plen = NLA_ALIGN(user_skb->len) - user_skb->len; | ||
445 | 472 | ||
446 | skb_copy_and_csum_dev(skb, nla_data(nla)); | 473 | if (plen > 0) |
474 | memset(skb_put(user_skb, plen), 0, plen); | ||
475 | } | ||
447 | 476 | ||
448 | genlmsg_end(user_skb, upcall); | 477 | ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len; |
449 | err = genlmsg_unicast(net, user_skb, upcall_info->portid); | ||
450 | 478 | ||
479 | err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid); | ||
451 | out: | 480 | out: |
452 | kfree_skb(nskb); | 481 | kfree_skb(nskb); |
453 | return err; | 482 | return err; |
454 | } | 483 | } |
455 | 484 | ||
456 | static void clear_stats(struct sw_flow *flow) | ||
457 | { | ||
458 | flow->used = 0; | ||
459 | flow->tcp_flags = 0; | ||
460 | flow->packet_count = 0; | ||
461 | flow->byte_count = 0; | ||
462 | } | ||
463 | |||
464 | static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) | 485 | static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) |
465 | { | 486 | { |
466 | struct ovs_header *ovs_header = info->userhdr; | 487 | struct ovs_header *ovs_header = info->userhdr; |
@@ -499,7 +520,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) | |||
499 | packet->protocol = htons(ETH_P_802_2); | 520 | packet->protocol = htons(ETH_P_802_2); |
500 | 521 | ||
501 | /* Build an sw_flow for sending this packet. */ | 522 | /* Build an sw_flow for sending this packet. */ |
502 | flow = ovs_flow_alloc(); | 523 | flow = ovs_flow_alloc(false); |
503 | err = PTR_ERR(flow); | 524 | err = PTR_ERR(flow); |
504 | if (IS_ERR(flow)) | 525 | if (IS_ERR(flow)) |
505 | goto err_kfree_skb; | 526 | goto err_kfree_skb; |
@@ -635,10 +656,10 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp, | |||
635 | const int skb_orig_len = skb->len; | 656 | const int skb_orig_len = skb->len; |
636 | struct nlattr *start; | 657 | struct nlattr *start; |
637 | struct ovs_flow_stats stats; | 658 | struct ovs_flow_stats stats; |
659 | __be16 tcp_flags; | ||
660 | unsigned long used; | ||
638 | struct ovs_header *ovs_header; | 661 | struct ovs_header *ovs_header; |
639 | struct nlattr *nla; | 662 | struct nlattr *nla; |
640 | unsigned long used; | ||
641 | u8 tcp_flags; | ||
642 | int err; | 663 | int err; |
643 | 664 | ||
644 | ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family, flags, cmd); | 665 | ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family, flags, cmd); |
@@ -667,24 +688,17 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp, | |||
667 | 688 | ||
668 | nla_nest_end(skb, nla); | 689 | nla_nest_end(skb, nla); |
669 | 690 | ||
670 | spin_lock_bh(&flow->lock); | 691 | ovs_flow_stats_get(flow, &stats, &used, &tcp_flags); |
671 | used = flow->used; | ||
672 | stats.n_packets = flow->packet_count; | ||
673 | stats.n_bytes = flow->byte_count; | ||
674 | tcp_flags = (u8)ntohs(flow->tcp_flags); | ||
675 | spin_unlock_bh(&flow->lock); | ||
676 | |||
677 | if (used && | 692 | if (used && |
678 | nla_put_u64(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used))) | 693 | nla_put_u64(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used))) |
679 | goto nla_put_failure; | 694 | goto nla_put_failure; |
680 | 695 | ||
681 | if (stats.n_packets && | 696 | if (stats.n_packets && |
682 | nla_put(skb, OVS_FLOW_ATTR_STATS, | 697 | nla_put(skb, OVS_FLOW_ATTR_STATS, sizeof(struct ovs_flow_stats), &stats)) |
683 | sizeof(struct ovs_flow_stats), &stats)) | ||
684 | goto nla_put_failure; | 698 | goto nla_put_failure; |
685 | 699 | ||
686 | if (tcp_flags && | 700 | if ((u8)ntohs(tcp_flags) && |
687 | nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, tcp_flags)) | 701 | nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, (u8)ntohs(tcp_flags))) |
688 | goto nla_put_failure; | 702 | goto nla_put_failure; |
689 | 703 | ||
690 | /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if | 704 | /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if |
@@ -701,8 +715,7 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp, | |||
701 | if (start) { | 715 | if (start) { |
702 | const struct sw_flow_actions *sf_acts; | 716 | const struct sw_flow_actions *sf_acts; |
703 | 717 | ||
704 | sf_acts = rcu_dereference_check(flow->sf_acts, | 718 | sf_acts = rcu_dereference_ovsl(flow->sf_acts); |
705 | lockdep_ovsl_is_held()); | ||
706 | 719 | ||
707 | err = ovs_nla_put_actions(sf_acts->actions, | 720 | err = ovs_nla_put_actions(sf_acts->actions, |
708 | sf_acts->actions_len, skb); | 721 | sf_acts->actions_len, skb); |
@@ -726,39 +739,34 @@ error: | |||
726 | return err; | 739 | return err; |
727 | } | 740 | } |
728 | 741 | ||
729 | static struct sk_buff *ovs_flow_cmd_alloc_info(struct sw_flow *flow) | 742 | static struct sk_buff *ovs_flow_cmd_alloc_info(struct sw_flow *flow, |
743 | struct genl_info *info) | ||
730 | { | 744 | { |
731 | const struct sw_flow_actions *sf_acts; | 745 | size_t len; |
732 | 746 | ||
733 | sf_acts = ovsl_dereference(flow->sf_acts); | 747 | len = ovs_flow_cmd_msg_size(ovsl_dereference(flow->sf_acts)); |
734 | 748 | ||
735 | return genlmsg_new(ovs_flow_cmd_msg_size(sf_acts), GFP_KERNEL); | 749 | return genlmsg_new_unicast(len, info, GFP_KERNEL); |
736 | } | 750 | } |
737 | 751 | ||
738 | static struct sk_buff *ovs_flow_cmd_build_info(struct sw_flow *flow, | 752 | static struct sk_buff *ovs_flow_cmd_build_info(struct sw_flow *flow, |
739 | struct datapath *dp, | 753 | struct datapath *dp, |
740 | u32 portid, u32 seq, u8 cmd) | 754 | struct genl_info *info, |
755 | u8 cmd) | ||
741 | { | 756 | { |
742 | struct sk_buff *skb; | 757 | struct sk_buff *skb; |
743 | int retval; | 758 | int retval; |
744 | 759 | ||
745 | skb = ovs_flow_cmd_alloc_info(flow); | 760 | skb = ovs_flow_cmd_alloc_info(flow, info); |
746 | if (!skb) | 761 | if (!skb) |
747 | return ERR_PTR(-ENOMEM); | 762 | return ERR_PTR(-ENOMEM); |
748 | 763 | ||
749 | retval = ovs_flow_cmd_fill_info(flow, dp, skb, portid, seq, 0, cmd); | 764 | retval = ovs_flow_cmd_fill_info(flow, dp, skb, info->snd_portid, |
765 | info->snd_seq, 0, cmd); | ||
750 | BUG_ON(retval < 0); | 766 | BUG_ON(retval < 0); |
751 | return skb; | 767 | return skb; |
752 | } | 768 | } |
753 | 769 | ||
754 | static struct sw_flow *__ovs_flow_tbl_lookup(struct flow_table *tbl, | ||
755 | const struct sw_flow_key *key) | ||
756 | { | ||
757 | u32 __always_unused n_mask_hit; | ||
758 | |||
759 | return ovs_flow_tbl_lookup(tbl, key, &n_mask_hit); | ||
760 | } | ||
761 | |||
762 | static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) | 770 | static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) |
763 | { | 771 | { |
764 | struct nlattr **a = info->attrs; | 772 | struct nlattr **a = info->attrs; |
@@ -770,6 +778,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) | |||
770 | struct datapath *dp; | 778 | struct datapath *dp; |
771 | struct sw_flow_actions *acts = NULL; | 779 | struct sw_flow_actions *acts = NULL; |
772 | struct sw_flow_match match; | 780 | struct sw_flow_match match; |
781 | bool exact_5tuple; | ||
773 | int error; | 782 | int error; |
774 | 783 | ||
775 | /* Extract key. */ | 784 | /* Extract key. */ |
@@ -778,7 +787,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) | |||
778 | goto error; | 787 | goto error; |
779 | 788 | ||
780 | ovs_match_init(&match, &key, &mask); | 789 | ovs_match_init(&match, &key, &mask); |
781 | error = ovs_nla_get_match(&match, | 790 | error = ovs_nla_get_match(&match, &exact_5tuple, |
782 | a[OVS_FLOW_ATTR_KEY], a[OVS_FLOW_ATTR_MASK]); | 791 | a[OVS_FLOW_ATTR_KEY], a[OVS_FLOW_ATTR_MASK]); |
783 | if (error) | 792 | if (error) |
784 | goto error; | 793 | goto error; |
@@ -809,7 +818,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) | |||
809 | goto err_unlock_ovs; | 818 | goto err_unlock_ovs; |
810 | 819 | ||
811 | /* Check if this is a duplicate flow */ | 820 | /* Check if this is a duplicate flow */ |
812 | flow = __ovs_flow_tbl_lookup(&dp->table, &key); | 821 | flow = ovs_flow_tbl_lookup(&dp->table, &key); |
813 | if (!flow) { | 822 | if (!flow) { |
814 | /* Bail out if we're not allowed to create a new flow. */ | 823 | /* Bail out if we're not allowed to create a new flow. */ |
815 | error = -ENOENT; | 824 | error = -ENOENT; |
@@ -817,12 +826,11 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) | |||
817 | goto err_unlock_ovs; | 826 | goto err_unlock_ovs; |
818 | 827 | ||
819 | /* Allocate flow. */ | 828 | /* Allocate flow. */ |
820 | flow = ovs_flow_alloc(); | 829 | flow = ovs_flow_alloc(!exact_5tuple); |
821 | if (IS_ERR(flow)) { | 830 | if (IS_ERR(flow)) { |
822 | error = PTR_ERR(flow); | 831 | error = PTR_ERR(flow); |
823 | goto err_unlock_ovs; | 832 | goto err_unlock_ovs; |
824 | } | 833 | } |
825 | clear_stats(flow); | ||
826 | 834 | ||
827 | flow->key = masked_key; | 835 | flow->key = masked_key; |
828 | flow->unmasked_key = key; | 836 | flow->unmasked_key = key; |
@@ -835,8 +843,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) | |||
835 | goto err_flow_free; | 843 | goto err_flow_free; |
836 | } | 844 | } |
837 | 845 | ||
838 | reply = ovs_flow_cmd_build_info(flow, dp, info->snd_portid, | 846 | reply = ovs_flow_cmd_build_info(flow, dp, info, OVS_FLOW_CMD_NEW); |
839 | info->snd_seq, OVS_FLOW_CMD_NEW); | ||
840 | } else { | 847 | } else { |
841 | /* We found a matching flow. */ | 848 | /* We found a matching flow. */ |
842 | struct sw_flow_actions *old_acts; | 849 | struct sw_flow_actions *old_acts; |
@@ -853,26 +860,19 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) | |||
853 | goto err_unlock_ovs; | 860 | goto err_unlock_ovs; |
854 | 861 | ||
855 | /* The unmasked key has to be the same for flow updates. */ | 862 | /* The unmasked key has to be the same for flow updates. */ |
856 | error = -EINVAL; | 863 | if (!ovs_flow_cmp_unmasked_key(flow, &match)) |
857 | if (!ovs_flow_cmp_unmasked_key(flow, &match)) { | ||
858 | OVS_NLERR("Flow modification message rejected, unmasked key does not match.\n"); | ||
859 | goto err_unlock_ovs; | 864 | goto err_unlock_ovs; |
860 | } | ||
861 | 865 | ||
862 | /* Update actions. */ | 866 | /* Update actions. */ |
863 | old_acts = ovsl_dereference(flow->sf_acts); | 867 | old_acts = ovsl_dereference(flow->sf_acts); |
864 | rcu_assign_pointer(flow->sf_acts, acts); | 868 | rcu_assign_pointer(flow->sf_acts, acts); |
865 | ovs_nla_free_flow_actions(old_acts); | 869 | ovs_nla_free_flow_actions(old_acts); |
866 | 870 | ||
867 | reply = ovs_flow_cmd_build_info(flow, dp, info->snd_portid, | 871 | reply = ovs_flow_cmd_build_info(flow, dp, info, OVS_FLOW_CMD_NEW); |
868 | info->snd_seq, OVS_FLOW_CMD_NEW); | ||
869 | 872 | ||
870 | /* Clear stats. */ | 873 | /* Clear stats. */ |
871 | if (a[OVS_FLOW_ATTR_CLEAR]) { | 874 | if (a[OVS_FLOW_ATTR_CLEAR]) |
872 | spin_lock_bh(&flow->lock); | 875 | ovs_flow_stats_clear(flow); |
873 | clear_stats(flow); | ||
874 | spin_unlock_bh(&flow->lock); | ||
875 | } | ||
876 | } | 876 | } |
877 | ovs_unlock(); | 877 | ovs_unlock(); |
878 | 878 | ||
@@ -910,7 +910,7 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info) | |||
910 | } | 910 | } |
911 | 911 | ||
912 | ovs_match_init(&match, &key, NULL); | 912 | ovs_match_init(&match, &key, NULL); |
913 | err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL); | 913 | err = ovs_nla_get_match(&match, NULL, a[OVS_FLOW_ATTR_KEY], NULL); |
914 | if (err) | 914 | if (err) |
915 | return err; | 915 | return err; |
916 | 916 | ||
@@ -921,14 +921,13 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info) | |||
921 | goto unlock; | 921 | goto unlock; |
922 | } | 922 | } |
923 | 923 | ||
924 | flow = __ovs_flow_tbl_lookup(&dp->table, &key); | 924 | flow = ovs_flow_tbl_lookup(&dp->table, &key); |
925 | if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) { | 925 | if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) { |
926 | err = -ENOENT; | 926 | err = -ENOENT; |
927 | goto unlock; | 927 | goto unlock; |
928 | } | 928 | } |
929 | 929 | ||
930 | reply = ovs_flow_cmd_build_info(flow, dp, info->snd_portid, | 930 | reply = ovs_flow_cmd_build_info(flow, dp, info, OVS_FLOW_CMD_NEW); |
931 | info->snd_seq, OVS_FLOW_CMD_NEW); | ||
932 | if (IS_ERR(reply)) { | 931 | if (IS_ERR(reply)) { |
933 | err = PTR_ERR(reply); | 932 | err = PTR_ERR(reply); |
934 | goto unlock; | 933 | goto unlock; |
@@ -965,17 +964,17 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info) | |||
965 | } | 964 | } |
966 | 965 | ||
967 | ovs_match_init(&match, &key, NULL); | 966 | ovs_match_init(&match, &key, NULL); |
968 | err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL); | 967 | err = ovs_nla_get_match(&match, NULL, a[OVS_FLOW_ATTR_KEY], NULL); |
969 | if (err) | 968 | if (err) |
970 | goto unlock; | 969 | goto unlock; |
971 | 970 | ||
972 | flow = __ovs_flow_tbl_lookup(&dp->table, &key); | 971 | flow = ovs_flow_tbl_lookup(&dp->table, &key); |
973 | if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) { | 972 | if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) { |
974 | err = -ENOENT; | 973 | err = -ENOENT; |
975 | goto unlock; | 974 | goto unlock; |
976 | } | 975 | } |
977 | 976 | ||
978 | reply = ovs_flow_cmd_alloc_info(flow); | 977 | reply = ovs_flow_cmd_alloc_info(flow, info); |
979 | if (!reply) { | 978 | if (!reply) { |
980 | err = -ENOMEM; | 979 | err = -ENOMEM; |
981 | goto unlock; | 980 | goto unlock; |
@@ -1061,6 +1060,7 @@ static const struct genl_ops dp_flow_genl_ops[] = { | |||
1061 | static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { | 1060 | static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { |
1062 | [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, | 1061 | [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, |
1063 | [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 }, | 1062 | [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 }, |
1063 | [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 }, | ||
1064 | }; | 1064 | }; |
1065 | 1065 | ||
1066 | static struct genl_family dp_datapath_genl_family = { | 1066 | static struct genl_family dp_datapath_genl_family = { |
@@ -1084,6 +1084,7 @@ static size_t ovs_dp_cmd_msg_size(void) | |||
1084 | msgsize += nla_total_size(IFNAMSIZ); | 1084 | msgsize += nla_total_size(IFNAMSIZ); |
1085 | msgsize += nla_total_size(sizeof(struct ovs_dp_stats)); | 1085 | msgsize += nla_total_size(sizeof(struct ovs_dp_stats)); |
1086 | msgsize += nla_total_size(sizeof(struct ovs_dp_megaflow_stats)); | 1086 | msgsize += nla_total_size(sizeof(struct ovs_dp_megaflow_stats)); |
1087 | msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */ | ||
1087 | 1088 | ||
1088 | return msgsize; | 1089 | return msgsize; |
1089 | } | 1090 | } |
@@ -1119,6 +1120,9 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb, | |||
1119 | &dp_megaflow_stats)) | 1120 | &dp_megaflow_stats)) |
1120 | goto nla_put_failure; | 1121 | goto nla_put_failure; |
1121 | 1122 | ||
1123 | if (nla_put_u32(skb, OVS_DP_ATTR_USER_FEATURES, dp->user_features)) | ||
1124 | goto nla_put_failure; | ||
1125 | |||
1122 | return genlmsg_end(skb, ovs_header); | 1126 | return genlmsg_end(skb, ovs_header); |
1123 | 1127 | ||
1124 | nla_put_failure: | 1128 | nla_put_failure: |
@@ -1127,17 +1131,17 @@ error: | |||
1127 | return -EMSGSIZE; | 1131 | return -EMSGSIZE; |
1128 | } | 1132 | } |
1129 | 1133 | ||
1130 | static struct sk_buff *ovs_dp_cmd_build_info(struct datapath *dp, u32 portid, | 1134 | static struct sk_buff *ovs_dp_cmd_build_info(struct datapath *dp, |
1131 | u32 seq, u8 cmd) | 1135 | struct genl_info *info, u8 cmd) |
1132 | { | 1136 | { |
1133 | struct sk_buff *skb; | 1137 | struct sk_buff *skb; |
1134 | int retval; | 1138 | int retval; |
1135 | 1139 | ||
1136 | skb = genlmsg_new(ovs_dp_cmd_msg_size(), GFP_KERNEL); | 1140 | skb = genlmsg_new_unicast(ovs_dp_cmd_msg_size(), info, GFP_KERNEL); |
1137 | if (!skb) | 1141 | if (!skb) |
1138 | return ERR_PTR(-ENOMEM); | 1142 | return ERR_PTR(-ENOMEM); |
1139 | 1143 | ||
1140 | retval = ovs_dp_cmd_fill_info(dp, skb, portid, seq, 0, cmd); | 1144 | retval = ovs_dp_cmd_fill_info(dp, skb, info->snd_portid, info->snd_seq, 0, cmd); |
1141 | if (retval < 0) { | 1145 | if (retval < 0) { |
1142 | kfree_skb(skb); | 1146 | kfree_skb(skb); |
1143 | return ERR_PTR(retval); | 1147 | return ERR_PTR(retval); |
@@ -1165,6 +1169,24 @@ static struct datapath *lookup_datapath(struct net *net, | |||
1165 | return dp ? dp : ERR_PTR(-ENODEV); | 1169 | return dp ? dp : ERR_PTR(-ENODEV); |
1166 | } | 1170 | } |
1167 | 1171 | ||
1172 | static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *info) | ||
1173 | { | ||
1174 | struct datapath *dp; | ||
1175 | |||
1176 | dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs); | ||
1177 | if (IS_ERR(dp)) | ||
1178 | return; | ||
1179 | |||
1180 | WARN(dp->user_features, "Dropping previously announced user features\n"); | ||
1181 | dp->user_features = 0; | ||
1182 | } | ||
1183 | |||
1184 | static void ovs_dp_change(struct datapath *dp, struct nlattr **a) | ||
1185 | { | ||
1186 | if (a[OVS_DP_ATTR_USER_FEATURES]) | ||
1187 | dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); | ||
1188 | } | ||
1189 | |||
1168 | static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) | 1190 | static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) |
1169 | { | 1191 | { |
1170 | struct nlattr **a = info->attrs; | 1192 | struct nlattr **a = info->attrs; |
@@ -1223,17 +1245,27 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) | |||
1223 | parms.port_no = OVSP_LOCAL; | 1245 | parms.port_no = OVSP_LOCAL; |
1224 | parms.upcall_portid = nla_get_u32(a[OVS_DP_ATTR_UPCALL_PID]); | 1246 | parms.upcall_portid = nla_get_u32(a[OVS_DP_ATTR_UPCALL_PID]); |
1225 | 1247 | ||
1248 | ovs_dp_change(dp, a); | ||
1249 | |||
1226 | vport = new_vport(&parms); | 1250 | vport = new_vport(&parms); |
1227 | if (IS_ERR(vport)) { | 1251 | if (IS_ERR(vport)) { |
1228 | err = PTR_ERR(vport); | 1252 | err = PTR_ERR(vport); |
1229 | if (err == -EBUSY) | 1253 | if (err == -EBUSY) |
1230 | err = -EEXIST; | 1254 | err = -EEXIST; |
1231 | 1255 | ||
1256 | if (err == -EEXIST) { | ||
1257 | /* An outdated user space instance that does not understand | ||
1258 | * the concept of user_features has attempted to create a new | ||
1259 | * datapath and is likely to reuse it. Drop all user features. | ||
1260 | */ | ||
1261 | if (info->genlhdr->version < OVS_DP_VER_FEATURES) | ||
1262 | ovs_dp_reset_user_features(skb, info); | ||
1263 | } | ||
1264 | |||
1232 | goto err_destroy_ports_array; | 1265 | goto err_destroy_ports_array; |
1233 | } | 1266 | } |
1234 | 1267 | ||
1235 | reply = ovs_dp_cmd_build_info(dp, info->snd_portid, | 1268 | reply = ovs_dp_cmd_build_info(dp, info, OVS_DP_CMD_NEW); |
1236 | info->snd_seq, OVS_DP_CMD_NEW); | ||
1237 | err = PTR_ERR(reply); | 1269 | err = PTR_ERR(reply); |
1238 | if (IS_ERR(reply)) | 1270 | if (IS_ERR(reply)) |
1239 | goto err_destroy_local_port; | 1271 | goto err_destroy_local_port; |
@@ -1253,7 +1285,7 @@ err_destroy_ports_array: | |||
1253 | err_destroy_percpu: | 1285 | err_destroy_percpu: |
1254 | free_percpu(dp->stats_percpu); | 1286 | free_percpu(dp->stats_percpu); |
1255 | err_destroy_table: | 1287 | err_destroy_table: |
1256 | ovs_flow_tbl_destroy(&dp->table); | 1288 | ovs_flow_tbl_destroy(&dp->table, false); |
1257 | err_free_dp: | 1289 | err_free_dp: |
1258 | release_net(ovs_dp_get_net(dp)); | 1290 | release_net(ovs_dp_get_net(dp)); |
1259 | kfree(dp); | 1291 | kfree(dp); |
@@ -1280,10 +1312,13 @@ static void __dp_destroy(struct datapath *dp) | |||
1280 | list_del_rcu(&dp->list_node); | 1312 | list_del_rcu(&dp->list_node); |
1281 | 1313 | ||
1282 | /* OVSP_LOCAL is datapath internal port. We need to make sure that | 1314 | /* OVSP_LOCAL is datapath internal port. We need to make sure that |
1283 | * all port in datapath are destroyed first before freeing datapath. | 1315 | * all ports in datapath are destroyed first before freeing datapath. |
1284 | */ | 1316 | */ |
1285 | ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL)); | 1317 | ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL)); |
1286 | 1318 | ||
1319 | /* RCU destroy the flow table */ | ||
1320 | ovs_flow_tbl_destroy(&dp->table, true); | ||
1321 | |||
1287 | call_rcu(&dp->rcu, destroy_dp_rcu); | 1322 | call_rcu(&dp->rcu, destroy_dp_rcu); |
1288 | } | 1323 | } |
1289 | 1324 | ||
@@ -1299,8 +1334,7 @@ static int ovs_dp_cmd_del(struct sk_buff *skb, struct genl_info *info) | |||
1299 | if (IS_ERR(dp)) | 1334 | if (IS_ERR(dp)) |
1300 | goto unlock; | 1335 | goto unlock; |
1301 | 1336 | ||
1302 | reply = ovs_dp_cmd_build_info(dp, info->snd_portid, | 1337 | reply = ovs_dp_cmd_build_info(dp, info, OVS_DP_CMD_DEL); |
1303 | info->snd_seq, OVS_DP_CMD_DEL); | ||
1304 | err = PTR_ERR(reply); | 1338 | err = PTR_ERR(reply); |
1305 | if (IS_ERR(reply)) | 1339 | if (IS_ERR(reply)) |
1306 | goto unlock; | 1340 | goto unlock; |
@@ -1328,8 +1362,9 @@ static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info) | |||
1328 | if (IS_ERR(dp)) | 1362 | if (IS_ERR(dp)) |
1329 | goto unlock; | 1363 | goto unlock; |
1330 | 1364 | ||
1331 | reply = ovs_dp_cmd_build_info(dp, info->snd_portid, | 1365 | ovs_dp_change(dp, info->attrs); |
1332 | info->snd_seq, OVS_DP_CMD_NEW); | 1366 | |
1367 | reply = ovs_dp_cmd_build_info(dp, info, OVS_DP_CMD_NEW); | ||
1333 | if (IS_ERR(reply)) { | 1368 | if (IS_ERR(reply)) { |
1334 | err = PTR_ERR(reply); | 1369 | err = PTR_ERR(reply); |
1335 | genl_set_err(&dp_datapath_genl_family, sock_net(skb->sk), 0, | 1370 | genl_set_err(&dp_datapath_genl_family, sock_net(skb->sk), 0, |
@@ -1360,8 +1395,7 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info) | |||
1360 | goto unlock; | 1395 | goto unlock; |
1361 | } | 1396 | } |
1362 | 1397 | ||
1363 | reply = ovs_dp_cmd_build_info(dp, info->snd_portid, | 1398 | reply = ovs_dp_cmd_build_info(dp, info, OVS_DP_CMD_NEW); |
1364 | info->snd_seq, OVS_DP_CMD_NEW); | ||
1365 | if (IS_ERR(reply)) { | 1399 | if (IS_ERR(reply)) { |
1366 | err = PTR_ERR(reply); | 1400 | err = PTR_ERR(reply); |
1367 | goto unlock; | 1401 | goto unlock; |
@@ -1441,7 +1475,7 @@ struct genl_family dp_vport_genl_family = { | |||
1441 | .parallel_ops = true, | 1475 | .parallel_ops = true, |
1442 | }; | 1476 | }; |
1443 | 1477 | ||
1444 | struct genl_multicast_group ovs_dp_vport_multicast_group = { | 1478 | static struct genl_multicast_group ovs_dp_vport_multicast_group = { |
1445 | .name = OVS_VPORT_MCGROUP | 1479 | .name = OVS_VPORT_MCGROUP |
1446 | }; | 1480 | }; |
1447 | 1481 | ||
@@ -1728,11 +1762,12 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1728 | int bucket = cb->args[0], skip = cb->args[1]; | 1762 | int bucket = cb->args[0], skip = cb->args[1]; |
1729 | int i, j = 0; | 1763 | int i, j = 0; |
1730 | 1764 | ||
1765 | rcu_read_lock(); | ||
1731 | dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); | 1766 | dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); |
1732 | if (!dp) | 1767 | if (!dp) { |
1768 | rcu_read_unlock(); | ||
1733 | return -ENODEV; | 1769 | return -ENODEV; |
1734 | 1770 | } | |
1735 | rcu_read_lock(); | ||
1736 | for (i = bucket; i < DP_VPORT_HASH_BUCKETS; i++) { | 1771 | for (i = bucket; i < DP_VPORT_HASH_BUCKETS; i++) { |
1737 | struct vport *vport; | 1772 | struct vport *vport; |
1738 | 1773 | ||