X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=datapath%2Fdatapath.c;h=71a44e6fcb4cd0201a5e753c33bf9b0d4153c09b;hb=3e9c481c70473b5faa29c72a1e609a31ddb6b990;hp=be16044d5a44a60ab6a751273187827aedbee8cc;hpb=1224e8fc1da9cddef6bdb24814300893bb2ace89;p=openvswitch diff --git a/datapath/datapath.c b/datapath/datapath.c index be16044d..71a44e6f 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -202,10 +202,14 @@ static int create_dp(int dp_idx, const char __user *devnamep) int i; if (devnamep) { - err = -EFAULT; - if (strncpy_from_user(devname, devnamep, IFNAMSIZ) < 0) + int retval = strncpy_from_user(devname, devnamep, IFNAMSIZ); + if (retval < 0) { + err = -EFAULT; goto err; - devname[IFNAMSIZ - 1] = '\0'; + } else if (retval >= IFNAMSIZ) { + err = -ENAMETOOLONG; + goto err; + } } else { snprintf(devname, sizeof devname, "of%d", dp_idx); } @@ -246,7 +250,8 @@ static int create_dp(int dp_idx, const char __user *devnamep) goto err_free_dp; /* Set up our datapath device. */ - strncpy(internal_dev_port.devname, devname, IFNAMSIZ - 1); + BUILD_BUG_ON(sizeof(internal_dev_port.devname) != sizeof(devname)); + strcpy(internal_dev_port.devname, devname); internal_dev_port.flags = ODP_PORT_INTERNAL; err = new_dp_port(dp, &internal_dev_port, ODPP_LOCAL); if (err) { @@ -423,8 +428,7 @@ got_port_no: if (err) goto out_unlock_dp; - if (!(port.flags & ODP_PORT_INTERNAL)) - set_internal_devs_mtu(dp); + set_internal_devs_mtu(dp); dp_sysfs_add_if(dp->ports[port_no]); err = __put_user(port_no, &portp->port); @@ -546,22 +550,9 @@ void dp_process_received_packet(struct dp_port *p, struct sk_buff *skb) } #if defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID) -/* This code is based on a skb_checksum_setup from net/dev/core.c from a - * combination of Lenny's 2.6.26 Xen kernel and Xen's - * linux-2.6.18-92.1.10.el5.xs5.0.0.394.644. We can't call this function - * directly because it isn't exported in all versions. */ -static int skb_pull_up_to(struct sk_buff *skb, void *ptr) -{ - if (ptr < (void *)skb->tail) - return 1; - if (__pskb_pull_tail(skb, - ptr - (void *)skb->data - skb_headlen(skb))) { - return 1; - } else { - return 0; - } -} - +/* This code is based on skb_checksum_setup() from Xen's net/dev/core.c. We + * can't call this function directly because it isn't exported in all + * versions. */ int vswitch_skb_checksum_setup(struct sk_buff *skb) { struct iphdr *iph; @@ -575,7 +566,7 @@ int vswitch_skb_checksum_setup(struct sk_buff *skb) if (skb->protocol != htons(ETH_P_IP)) goto out; - if (!skb_pull_up_to(skb, skb_network_header(skb) + sizeof(struct iphdr))) + if (!pskb_may_pull(skb, skb_network_header(skb) + sizeof(struct iphdr) - skb->data)) goto out; iph = ip_hdr(skb); @@ -597,7 +588,7 @@ int vswitch_skb_checksum_setup(struct sk_buff *skb) goto out; } - if (!skb_pull_up_to(skb, th + csum_offset + 2)) + if (!pskb_may_pull(skb, th + csum_offset + 2 - skb->data)) goto out; skb->ip_summed = CHECKSUM_PARTIAL; @@ -1366,7 +1357,7 @@ int dp_min_mtu(const struct datapath *dp) } /* Sets the MTU of all datapath devices to the minimum of the ports. Must - * be called with RTNL lock and dp_mutex. */ + * be called with RTNL lock. */ void set_internal_devs_mtu(const struct datapath *dp) { struct dp_port *p;