X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=datapath%2Fdatapath.c;h=b19123975ad1cca2fec2a958a734e3e048fb2840;hb=0c58c0c4da31b554e88be581cca39d314ded9b6b;hp=05875dc1875b12692fe1f4861b42a852ddd98092;hpb=a4af24751b4127ae0c5cb25262b4069a7c0842ae;p=openvswitch diff --git a/datapath/datapath.c b/datapath/datapath.c index 05875dc1..b1912397 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -53,6 +53,11 @@ #include "vlan.h" #include "vport-internal_dev.h" +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) || \ + LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0) +#error Kernels before 2.6.18 or after 3.0 are not supported by this version of Open vSwitch. +#endif + int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd); EXPORT_SYMBOL(dp_ioctl_hook); @@ -79,7 +84,7 @@ EXPORT_SYMBOL(dp_ioctl_hook); static LIST_HEAD(dps); static struct vport *new_vport(const struct vport_parms *); -static int queue_control_packets(struct datapath *, struct sk_buff *, +static int queue_userspace_packets(struct datapath *, struct sk_buff *, const struct dp_upcall_info *); /* Must be called with rcu_read_lock, genl_mutex, or RTNL lock. */ @@ -273,24 +278,25 @@ void dp_process_received_packet(struct vport *p, struct sk_buff *skb) if (!OVS_CB(skb)->flow) { struct sw_flow_key key; struct tbl_node *flow_node; + int key_len; bool is_frag; /* Extract flow from 'skb' into 'key'. */ - error = flow_extract(skb, p->port_no, &key, &is_frag); + error = flow_extract(skb, p->port_no, &key, &key_len, &is_frag); if (unlikely(error)) { kfree_skb(skb); return; } if (is_frag && dp->drop_frags) { - kfree_skb(skb); + consume_skb(skb); stats_counter_off = offsetof(struct dp_stats_percpu, n_frags); goto out; } /* Look up flow. */ - flow_node = tbl_lookup(rcu_dereference(dp->table), &key, - flow_hash(&key), flow_cmp); + flow_node = tbl_lookup(rcu_dereference(dp->table), &key, key_len, + flow_hash(&key, key_len), flow_cmp); if (unlikely(!flow_node)) { struct dp_upcall_info upcall; @@ -393,33 +399,28 @@ int dp_upcall(struct datapath *dp, struct sk_buff *skb, const struct dp_upcall_i WARN_ON_ONCE(skb_shared(skb)); - forward_ip_summed(skb); - - err = vswitch_skb_checksum_setup(skb); - if (err) - goto err_kfree_skb; + forward_ip_summed(skb, true); /* Break apart GSO packets into their component pieces. Otherwise * userspace may try to stuff a 64kB packet into a 1500-byte MTU. */ if (skb_is_gso(skb)) { struct sk_buff *nskb = skb_gso_segment(skb, NETIF_F_SG | NETIF_F_HW_CSUM); - kfree_skb(skb); - skb = nskb; - if (IS_ERR(skb)) { - err = PTR_ERR(skb); + if (IS_ERR(nskb)) { + kfree_skb(skb); + err = PTR_ERR(nskb); goto err; } + consume_skb(skb); + skb = nskb; } - err = queue_control_packets(dp, skb, upcall_info); + err = queue_userspace_packets(dp, skb, upcall_info); if (err) goto err; return 0; -err_kfree_skb: - kfree_skb(skb); err: local_bh_disable(); stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id()); @@ -437,19 +438,13 @@ err: * 'upcall_info'. There will be only one packet unless we broke up a GSO * packet. */ -static int queue_control_packets(struct datapath *dp, struct sk_buff *skb, +static int queue_userspace_packets(struct datapath *dp, struct sk_buff *skb, const struct dp_upcall_info *upcall_info) { u32 group = packet_mc_group(dp, upcall_info->cmd); struct sk_buff *nskb; - int port_no; int err; - if (OVS_CB(skb)->vport) - port_no = OVS_CB(skb)->vport->port_no; - else - port_no = ODPP_LOCAL; - do { struct odp_header *upcall; struct sk_buff *user_skb; /* to be queued to userspace */ @@ -512,7 +507,7 @@ static int queue_control_packets(struct datapath *dp, struct sk_buff *skb, if (err) goto err_kfree_skbs; - kfree_skb(skb); + consume_skb(skb); skb = nskb; } while (skb); return 0; @@ -557,7 +552,7 @@ static int validate_actions(const struct nlattr *attr) nla_for_each_nested(a, attr, rem) { static const u32 action_lens[ODP_ACTION_ATTR_MAX + 1] = { [ODP_ACTION_ATTR_OUTPUT] = 4, - [ODP_ACTION_ATTR_CONTROLLER] = 8, + [ODP_ACTION_ATTR_USERSPACE] = 8, [ODP_ACTION_ATTR_SET_DL_TCI] = 2, [ODP_ACTION_ATTR_STRIP_VLAN] = 0, [ODP_ACTION_ATTR_SET_DL_SRC] = ETH_ALEN, @@ -570,7 +565,6 @@ static int validate_actions(const struct nlattr *attr) [ODP_ACTION_ATTR_SET_TUNNEL] = 8, [ODP_ACTION_ATTR_SET_PRIORITY] = 4, [ODP_ACTION_ATTR_POP_PRIORITY] = 0, - [ODP_ACTION_ATTR_DROP_SPOOFED_ARP] = 0, }; int type = nla_type(a); @@ -581,7 +575,7 @@ static int validate_actions(const struct nlattr *attr) case ODP_ACTION_ATTR_UNSPEC: return -EINVAL; - case ODP_ACTION_ATTR_CONTROLLER: + case ODP_ACTION_ATTR_USERSPACE: case ODP_ACTION_ATTR_STRIP_VLAN: case ODP_ACTION_ATTR_SET_DL_SRC: case ODP_ACTION_ATTR_SET_DL_DST: @@ -592,7 +586,6 @@ static int validate_actions(const struct nlattr *attr) case ODP_ACTION_ATTR_SET_TUNNEL: case ODP_ACTION_ATTR_SET_PRIORITY: case ODP_ACTION_ATTR_POP_PRIORITY: - case ODP_ACTION_ATTR_DROP_SPOOFED_ARP: /* No validation needed. */ break; @@ -636,11 +629,13 @@ static int expand_table(struct datapath *dp) struct tbl *new_table; new_table = tbl_expand(old_table); - if (IS_ERR(new_table)) - return PTR_ERR(new_table); - - rcu_assign_pointer(dp->table, new_table); - tbl_deferred_destroy(old_table, NULL); + if (IS_ERR(new_table)) { + if (PTR_ERR(new_table) != -ENOSPC) + return PTR_ERR(new_table); + } else { + rcu_assign_pointer(dp->table, new_table); + tbl_deferred_destroy(old_table, NULL); + } return 0; } @@ -657,9 +652,11 @@ static int odp_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) bool is_frag; int len; int err; + int key_len; err = -EINVAL; - if (!a[ODP_PACKET_ATTR_PACKET] || !a[ODP_PACKET_ATTR_ACTIONS] || + if (!a[ODP_PACKET_ATTR_PACKET] || !a[ODP_PACKET_ATTR_KEY] || + !a[ODP_PACKET_ATTR_ACTIONS] || nla_len(a[ODP_PACKET_ATTR_PACKET]) < ETH_HLEN) goto err; @@ -693,10 +690,16 @@ static int odp_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) if (IS_ERR(flow)) goto err_kfree_skb; - err = flow_extract(packet, -1, &flow->key, &is_frag); + err = flow_extract(packet, -1, &flow->key, &key_len, &is_frag); + if (err) + goto err_flow_put; + flow->tbl_node.hash = flow_hash(&flow->key, key_len); + + err = flow_metadata_from_nlattrs(&flow->key.eth.in_port, + &flow->key.eth.tun_id, + a[ODP_PACKET_ATTR_KEY]); if (err) goto err_flow_put; - flow->tbl_node.hash = flow_hash(&flow->key); acts = flow_actions_alloc(a[ODP_PACKET_ATTR_ACTIONS]); err = PTR_ERR(acts); @@ -729,6 +732,7 @@ err: static const struct nla_policy packet_policy[ODP_PACKET_ATTR_MAX + 1] = { [ODP_PACKET_ATTR_PACKET] = { .type = NLA_UNSPEC }, + [ODP_PACKET_ATTR_KEY] = { .type = NLA_NESTED }, [ODP_PACKET_ATTR_ACTIONS] = { .type = NLA_NESTED }, }; @@ -743,6 +747,9 @@ static struct genl_ops dp_packet_genl_ops[] = { static void get_dp_stats(struct datapath *dp, struct odp_stats *stats) { int i; + struct tbl *table = get_table_protected(dp); + + stats->n_flows = tbl_count(table); stats->n_frags = stats->n_hit = stats->n_missed = stats->n_lost = 0; for_each_possible_cpu(i) { @@ -941,12 +948,13 @@ static int odp_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) struct tbl *table; u32 hash; int error; + int key_len; /* Extract key. */ error = -EINVAL; if (!a[ODP_FLOW_ATTR_KEY]) goto error; - error = flow_from_nlattrs(&key, a[ODP_FLOW_ATTR_KEY]); + error = flow_from_nlattrs(&key, &key_len, a[ODP_FLOW_ATTR_KEY]); if (error) goto error; @@ -965,9 +973,9 @@ static int odp_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) if (!dp) goto error; - hash = flow_hash(&key); + hash = flow_hash(&key, key_len); table = get_table_protected(dp); - flow_node = tbl_lookup(table, &key, hash, flow_cmp); + flow_node = tbl_lookup(table, &key, key_len, hash, flow_cmp); if (!flow_node) { struct sw_flow_actions *acts; @@ -1077,10 +1085,11 @@ static int odp_flow_cmd_get(struct sk_buff *skb, struct genl_info *info) struct datapath *dp; struct tbl *table; int err; + int key_len; if (!a[ODP_FLOW_ATTR_KEY]) return -EINVAL; - err = flow_from_nlattrs(&key, a[ODP_FLOW_ATTR_KEY]); + err = flow_from_nlattrs(&key, &key_len, a[ODP_FLOW_ATTR_KEY]); if (err) return err; @@ -1089,7 +1098,8 @@ static int odp_flow_cmd_get(struct sk_buff *skb, struct genl_info *info) return -ENODEV; table = get_table_protected(dp); - flow_node = tbl_lookup(table, &key, flow_hash(&key), flow_cmp); + flow_node = tbl_lookup(table, &key, key_len, flow_hash(&key, key_len), + flow_cmp); if (!flow_node) return -ENOENT; @@ -1112,10 +1122,11 @@ static int odp_flow_cmd_del(struct sk_buff *skb, struct genl_info *info) struct datapath *dp; struct tbl *table; int err; + int key_len; if (!a[ODP_FLOW_ATTR_KEY]) return flush_flows(odp_header->dp_ifindex); - err = flow_from_nlattrs(&key, a[ODP_FLOW_ATTR_KEY]); + err = flow_from_nlattrs(&key, &key_len, a[ODP_FLOW_ATTR_KEY]); if (err) return err; @@ -1124,7 +1135,8 @@ static int odp_flow_cmd_del(struct sk_buff *skb, struct genl_info *info) return -ENODEV; table = get_table_protected(dp); - flow_node = tbl_lookup(table, &key, flow_hash(&key), flow_cmp); + flow_node = tbl_lookup(table, &key, key_len, flow_hash(&key, key_len), + flow_cmp); if (!flow_node) return -ENOENT; flow = flow_cast(flow_node); @@ -1903,7 +1915,9 @@ static int odp_vport_cmd_get(struct sk_buff *skb, struct genl_info *info) if (IS_ERR(reply)) goto exit_unlock; - err = genlmsg_reply(reply, info); + rcu_read_unlock(); + + return genlmsg_reply(reply, info); exit_unlock: rcu_read_unlock();