X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=datapath%2Fdatapath.c;h=e927b2469515938fe9f5e08f5c1bfa5debf32076;hb=cb5087caddd187e71d5f32118d8d807c9c131725;hp=3edba7ce5589a6d047311fea9a9c7592a8566c3c;hpb=a5e54d9b6f8002f34cc792df69e6eda68cf95223;p=openvswitch diff --git a/datapath/datapath.c b/datapath/datapath.c index 3edba7ce..e927b246 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -55,22 +55,8 @@ int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd); EXPORT_SYMBOL(dp_ioctl_hook); -int (*dp_add_dp_hook)(struct datapath *dp); -EXPORT_SYMBOL(dp_add_dp_hook); - -int (*dp_del_dp_hook)(struct datapath *dp); -EXPORT_SYMBOL(dp_del_dp_hook); - -int (*dp_add_if_hook)(struct net_bridge_port *p); -EXPORT_SYMBOL(dp_add_if_hook); - -int (*dp_del_if_hook)(struct net_bridge_port *p); -EXPORT_SYMBOL(dp_del_if_hook); - /* Datapaths. Protected on the read side by rcu_read_lock, on the write side - * by dp_mutex. dp_mutex is almost completely redundant with genl_mutex - * maintained by the Generic Netlink code, but the timeout path needs mutual - * exclusion too. + * by dp_mutex. * * dp_mutex nests inside the RTNL lock: if you need both you must take the RTNL * lock first. @@ -184,6 +170,16 @@ errout: rtnl_set_sk_err(net, RTNLGRP_LINK, err); } +static void release_dp(struct kobject *kobj) +{ + struct datapath *dp = container_of(kobj, struct datapath, ifobj); + kfree(dp); +} + +struct kobj_type dp_ktype = { + .release = release_dp +}; + static int create_dp(int dp_idx, const char __user *devnamep) { struct net_device *dp_dev; @@ -225,6 +221,11 @@ static int create_dp(int dp_idx, const char __user *devnamep) skb_queue_head_init(&dp->queues[i]); init_waitqueue_head(&dp->waitqueue); + /* Initialize kobject for bridge. This will be added as + * /sys/class/net//brif later, if sysfs is enabled. */ + dp->ifobj.kset = NULL; + kobject_init(&dp->ifobj, &dp_ktype); + /* Allocate table. */ err = -ENOMEM; rcu_assign_pointer(dp->table, dp_table_create(DP_L1_SIZE)); @@ -252,8 +253,7 @@ static int create_dp(int dp_idx, const char __user *devnamep) mutex_unlock(&dp_mutex); rtnl_unlock(); - if (dp_add_dp_hook) - dp_add_dp_hook(dp); + dp_sysfs_add_dp(dp); return 0; @@ -281,8 +281,7 @@ static void do_destroy_dp(struct datapath *dp) if (p->port_no != ODPP_LOCAL) dp_del_port(p); - if (dp_del_dp_hook) - dp_del_dp_hook(dp); + dp_sysfs_del_dp(dp); rcu_assign_pointer(dps[dp->dp_idx], NULL); @@ -295,7 +294,7 @@ static void do_destroy_dp(struct datapath *dp) for (i = 0; i < DP_MAX_GROUPS; i++) kfree(dp->groups[i]); free_percpu(dp->stats_percpu); - kfree(dp); + kobject_put(&dp->ifobj); module_put(THIS_MODULE); } @@ -320,6 +319,19 @@ err_unlock: return err; } +static void release_nbp(struct kobject *kobj) +{ + struct net_bridge_port *p = container_of(kobj, struct net_bridge_port, kobj); + kfree(p); +} + +struct kobj_type brport_ktype = { +#ifdef CONFIG_SYSFS + .sysfs_ops = &brport_sysfs_ops, +#endif + .release = release_nbp +}; + /* Called with RTNL lock and dp_mutex. */ static int new_nbp(struct datapath *dp, struct net_device *dev, int port_no) { @@ -349,6 +361,11 @@ static int new_nbp(struct datapath *dp, struct net_device *dev, int port_no) list_add_rcu(&p->node, &dp->port_list); dp->n_ports++; + /* Initialize kobject for bridge. This will be added as + * /sys/class/net//brport later, if sysfs is enabled. */ + p->kobj.kset = NULL; + kobject_init(&p->kobj, &brport_ktype); + dp_ifinfo_notify(RTM_NEWLINK, p); return 0; @@ -376,7 +393,7 @@ static int add_port(int dp_idx, struct odp_port __user *portp) for (port_no = 1; port_no < DP_MAX_PORTS; port_no++) if (!dp->ports[port_no]) goto got_port_no; - err = -EXFULL; + err = -EFBIG; goto out_unlock_dp; got_port_no: @@ -402,8 +419,7 @@ got_port_no: if (err) goto out_put; - if (dp_add_if_hook) - dp_add_if_hook(dp->ports[port_no]); + dp_sysfs_add_if(dp->ports[port_no]); err = __put_user(port_no, &port.port); @@ -421,13 +437,8 @@ int dp_del_port(struct net_bridge_port *p) { ASSERT_RTNL(); - if (p->port_no != ODPP_LOCAL && dp_del_if_hook) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) - sysfs_remove_link(&p->dp->ifobj, p->dev->name); -#else - sysfs_remove_link(p->dp->ifobj, p->dev->name); -#endif - } + if (p->port_no != ODPP_LOCAL) + dp_sysfs_del_if(p); dp_ifinfo_notify(RTM_DELLINK, p); p->dp->n_ports--; @@ -448,15 +459,10 @@ int dp_del_port(struct net_bridge_port *p) /* Then wait until no one is still using it, and destroy it. */ synchronize_rcu(); - if (is_dp_dev(p->dev)) { + if (is_dp_dev(p->dev)) dp_dev_destroy(p->dev); - } - if (p->port_no != ODPP_LOCAL && dp_del_if_hook) { - dp_del_if_hook(p); - } else { - dev_put(p->dev); - kfree(p); - } + dev_put(p->dev); + kobject_put(&p->kobj); return 0; } @@ -568,8 +574,7 @@ static int dp_frame_hook(struct net_bridge_port *p, struct sk_buff **pskb) #error #endif -#ifdef CONFIG_XEN -#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,18) +#if defined(CONFIG_XEN) && LINUX_VERSION_CODE == KERNEL_VERSION(2,6,18) /* This code is copied verbatim from net/dev/core.c in Xen's * linux-2.6.18-92.1.10.el5.xs5.0.0.394.644. We can't call those functions * directly because they aren't exported. */ @@ -585,7 +590,7 @@ static int skb_pull_up_to(struct sk_buff *skb, void *ptr) } } -int skb_checksum_setup(struct sk_buff *skb) +int vswitch_skb_checksum_setup(struct sk_buff *skb) { if (skb->proto_csum_blank) { if (skb->protocol != htons(ETH_P_IP)) @@ -616,8 +621,90 @@ int skb_checksum_setup(struct sk_buff *skb) out: return -EPROTO; } -#endif /* linux == 2.6.18 */ -#endif /* CONFIG_XEN */ +#else +int vswitch_skb_checksum_setup(struct sk_buff *skb) { return 0; } +#endif /* CONFIG_XEN && linux == 2.6.18 */ + +/* Append each packet in 'skb' list to 'queue'. There will be only one packet + * unless we broke up a GSO packet. */ +static int +queue_control_packets(struct sk_buff *skb, struct sk_buff_head *queue, + int queue_no, u32 arg) +{ + struct sk_buff *nskb; + int port_no; + int err; + + port_no = ODPP_LOCAL; + if (skb->dev) { + if (skb->dev->br_port) + port_no = skb->dev->br_port->port_no; + else if (is_dp_dev(skb->dev)) + port_no = dp_dev_priv(skb->dev)->port_no; + } + + do { + struct odp_msg *header; + + nskb = skb->next; + skb->next = NULL; + + /* If a checksum-deferred packet is forwarded to the + * controller, correct the pointers and checksum. This happens + * on a regular basis only on Xen, on which VMs can pass up + * packets that do not have their checksum computed. + */ + err = vswitch_skb_checksum_setup(skb); + if (err) + goto err_kfree_skbs; +#ifndef CHECKSUM_HW + if (skb->ip_summed == CHECKSUM_PARTIAL) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) + /* Until 2.6.22, the start of the transport header was + * also the start of data to be checksummed. Linux + * 2.6.22 introduced the csum_start field for this + * purpose, but we should point the transport header to + * it anyway for backward compatibility, as + * dev_queue_xmit() does even in 2.6.28. */ + skb_set_transport_header(skb, skb->csum_start - + skb_headroom(skb)); +#endif + err = skb_checksum_help(skb); + if (err) + goto err_kfree_skbs; + } +#else + if (skb->ip_summed == CHECKSUM_HW) { + err = skb_checksum_help(skb, 0); + if (err) + goto err_kfree_skbs; + } +#endif + + err = skb_cow(skb, sizeof *header); + if (err) + goto err_kfree_skbs; + + header = (struct odp_msg*)__skb_push(skb, sizeof *header); + header->type = queue_no; + header->length = skb->len; + header->port = port_no; + header->reserved = 0; + header->arg = arg; + skb_queue_tail(queue, skb); + + skb = nskb; + } while (skb); + return 0; + +err_kfree_skbs: + kfree_skb(skb); + while ((skb = nskb) != NULL) { + nskb = skb->next; + kfree_skb(skb); + } + return err; +} int dp_output_control(struct datapath *dp, struct sk_buff *skb, int queue_no, @@ -625,7 +712,6 @@ dp_output_control(struct datapath *dp, struct sk_buff *skb, int queue_no, { struct dp_stats_percpu *stats; struct sk_buff_head *queue; - int port_no; int err; WARN_ON_ONCE(skb_shared(skb)); @@ -636,40 +722,6 @@ dp_output_control(struct datapath *dp, struct sk_buff *skb, int queue_no, if (skb_queue_len(queue) >= DP_MAX_QUEUE_LEN) goto err_kfree_skb; - /* If a checksum-deferred packet is forwarded to the controller, - * correct the pointers and checksum. This happens on a regular basis - * only on Xen (the CHECKSUM_HW case), on which VMs can pass up packets - * that do not have their checksum computed. We also implement it for - * the non-Xen case, but it is difficult to trigger or test this case - * there, hence the WARN_ON_ONCE(). - */ - err = skb_checksum_setup(skb); - if (err) - goto err_kfree_skb; -#ifndef CHECKSUM_HW - if (skb->ip_summed == CHECKSUM_PARTIAL) { - WARN_ON_ONCE(1); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) - /* Until 2.6.22, the start of the transport header was also the - * start of data to be checksummed. Linux 2.6.22 introduced - * the csum_start field for this purpose, but we should point - * the transport header to it anyway for backward - * compatibility, as dev_queue_xmit() does even in 2.6.28. */ - skb_set_transport_header(skb, skb->csum_start - - skb_headroom(skb)); -#endif - err = skb_checksum_help(skb); - if (err) - goto err_kfree_skb; - } -#else - if (skb->ip_summed == CHECKSUM_HW) { - err = skb_checksum_help(skb, 0); - if (err) - goto err_kfree_skb; - } -#endif - /* 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)) { @@ -687,45 +739,9 @@ dp_output_control(struct datapath *dp, struct sk_buff *skb, int queue_no, } } - /* Figure out port number. */ - port_no = ODPP_LOCAL; - if (skb->dev) { - if (skb->dev->br_port) - port_no = skb->dev->br_port->port_no; - else if (is_dp_dev(skb->dev)) - port_no = dp_dev_priv(skb->dev)->port_no; - } - - /* Append each packet to queue. There will be only one packet unless - * we broke up a GSO packet above. */ - do { - struct odp_msg *header; - struct sk_buff *nskb = skb->next; - skb->next = NULL; - - err = skb_cow(skb, sizeof *header); - if (err) { - while (nskb) { - kfree_skb(skb); - skb = nskb; - nskb = skb->next; - } - goto err_kfree_skb; - } - - header = (struct odp_msg*)__skb_push(skb, sizeof *header); - header->type = queue_no; - header->length = skb->len; - header->port = port_no; - header->reserved = 0; - header->arg = arg; - skb_queue_tail(queue, skb); - - skb = nskb; - } while (skb); - + err = queue_control_packets(skb, queue, queue_no, arg); wake_up_interruptible(&dp->waitqueue); - return 0; + return err; err_kfree_skb: kfree_skb(skb); @@ -834,7 +850,7 @@ static void clear_stats(struct sw_flow *flow) static int put_flow(struct datapath *dp, struct odp_flow_put __user *ufp) { struct odp_flow_put uf; - struct sw_flow *flow, **bucket; + struct sw_flow *flow; struct dp_table *table; struct odp_flow_stats stats; int error; @@ -844,15 +860,10 @@ static int put_flow(struct datapath *dp, struct odp_flow_put __user *ufp) goto error; uf.flow.key.reserved = 0; -retry: table = rcu_dereference(dp->table); - bucket = dp_table_lookup_for_insert(table, &uf.flow.key); - if (!bucket) { - /* No such flow, and the slots where it could go are full. */ - error = uf.flags & ODPPF_CREATE ? -EXFULL : -ENOENT; - goto error; - } else if (!*bucket) { - /* No such flow, but we found an available slot for it. */ + flow = dp_table_lookup(table, &uf.flow.key); + if (!flow) { + /* No such flow. */ struct sw_flow_actions *acts; error = -ENOENT; @@ -860,14 +871,15 @@ retry: goto error; /* Expand table, if necessary, to make room. */ - if (dp->n_flows * 4 >= table->n_buckets && - table->n_buckets < DP_MAX_BUCKETS) { + if (dp->n_flows >= table->n_buckets) { + error = -ENOSPC; + if (table->n_buckets >= DP_MAX_BUCKETS) + goto error; + error = dp_table_expand(dp); if (error) goto error; - - /* The bucket's location has changed. Try again. */ - goto retry; + table = rcu_dereference(dp->table); } /* Allocate flow. */ @@ -887,12 +899,13 @@ retry: rcu_assign_pointer(flow->sf_acts, acts); /* Put flow in bucket. */ - rcu_assign_pointer(*bucket, flow); + error = dp_table_insert(table, flow); + if (error) + goto error_free_flow_acts; dp->n_flows++; memset(&stats, 0, sizeof(struct odp_flow_stats)); } else { /* We found a matching flow. */ - struct sw_flow *flow = *rcu_dereference(bucket); struct sw_flow_actions *old_acts, *new_acts; unsigned long int flags; @@ -930,6 +943,8 @@ retry: return -EFAULT; return 0; +error_free_flow_acts: + kfree(flow->sf_acts); error_free_flow: kmem_cache_free(flow_cache, flow); error: @@ -1103,6 +1118,7 @@ static int do_execute(struct datapath *dp, const struct odp_execute *executep) struct odp_flow_key key; struct sk_buff *skb; struct sw_flow_actions *actions; + struct ethhdr *eth; int err; err = -EFAULT; @@ -1142,6 +1158,17 @@ static int do_execute(struct datapath *dp, const struct odp_execute *executep) execute.length)) goto error_free_skb; + skb_reset_mac_header(skb); + eth = eth_hdr(skb); + + /* Normally, setting the skb 'protocol' field would be handled by a + * call to eth_type_trans(), but it assumes there's a sending + * device, which we may not have. */ + if (ntohs(eth->h_proto) >= 1536) + skb->protocol = eth->h_proto; + else + skb->protocol = htons(ETH_P_802_2); + flow_extract(skb, execute.in_port, &key); err = execute_actions(dp, skb, &key, actions->actions, actions->n_actions, GFP_KERNEL); @@ -1162,8 +1189,8 @@ static int get_dp_stats(struct datapath *dp, struct odp_stats __user *statsp) int i; stats.n_flows = dp->n_flows; - stats.cur_capacity = rcu_dereference(dp->table)->n_buckets * 2; - stats.max_capacity = DP_MAX_BUCKETS * 2; + stats.cur_capacity = rcu_dereference(dp->table)->n_buckets; + stats.max_capacity = DP_MAX_BUCKETS; stats.n_ports = dp->n_ports; stats.max_ports = DP_MAX_PORTS; stats.max_groups = DP_MAX_GROUPS; @@ -1181,6 +1208,29 @@ static int get_dp_stats(struct datapath *dp, struct odp_stats __user *statsp) return copy_to_user(statsp, &stats, sizeof stats) ? -EFAULT : 0; } +/* MTU of the dp pseudo-device: ETH_DATA_LEN or the minimum of the ports */ +int dp_min_mtu(const struct datapath *dp) +{ + struct net_bridge_port *p; + int mtu = 0; + + ASSERT_RTNL(); + + list_for_each_entry_rcu (p, &dp->port_list, node) { + struct net_device *dev = p->dev; + + /* Skip any internal ports, since that's what we're trying to + * set. */ + if (is_dp_dev(dev)) + continue; + + if (!mtu || dev->mtu < mtu) + mtu = dev->mtu; + } + + return mtu ? mtu : ETH_DATA_LEN; +} + static int put_port(const struct net_bridge_port *p, struct odp_port __user *uop) {