datapath: Require explicit upcall_pid for new datapaths and vports.
authorBen Pfaff <blp@nicira.com>
Wed, 12 Oct 2011 18:04:10 +0000 (11:04 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 12 Oct 2011 23:27:08 +0000 (16:27 -0700)
This increases consistency with the OVS_ACTION_ATTR_USERSPACE action, which
also requires an explicit pid.

Suggested-by: Jesse Gross <jesse@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath/datapath.c
lib/dpif-linux.c

index 551b384ad0bfb8728ac530f32d7decb5f9534144..950bed1b703be863468c150b81b2a7b53f89781d 100644 (file)
@@ -1282,7 +1282,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
        int err;
 
        err = -EINVAL;
-       if (!a[OVS_DP_ATTR_NAME])
+       if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
                goto err;
 
        err = ovs_dp_cmd_validate(a);
@@ -1326,10 +1326,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
        parms.options = NULL;
        parms.dp = dp;
        parms.port_no = OVSP_LOCAL;
-       if (a[OVS_DP_ATTR_UPCALL_PID])
-               parms.upcall_pid = nla_get_u32(a[OVS_DP_ATTR_UPCALL_PID]);
-       else
-               parms.upcall_pid = NETLINK_CB(skb).pid;
+       parms.upcall_pid = nla_get_u32(a[OVS_DP_ATTR_UPCALL_PID]);
 
        vport = new_vport(&parms);
        if (IS_ERR(vport)) {
@@ -1664,7 +1661,8 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
        int err;
 
        err = -EINVAL;
-       if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE])
+       if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
+           !a[OVS_VPORT_ATTR_UPCALL_PID])
                goto exit;
 
        err = ovs_vport_cmd_validate(a);
@@ -1705,10 +1703,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
        parms.options = a[OVS_VPORT_ATTR_OPTIONS];
        parms.dp = dp;
        parms.port_no = port_no;
-       if (a[OVS_VPORT_ATTR_UPCALL_PID])
-               parms.upcall_pid = nla_get_u32(a[OVS_VPORT_ATTR_UPCALL_PID]);
-       else
-               parms.upcall_pid = NETLINK_CB(skb).pid;
+       parms.upcall_pid = nla_get_u32(a[OVS_VPORT_ATTR_UPCALL_PID]);
 
        vport = new_vport(&parms);
        err = PTR_ERR(vport);
index 1e1afe50a2ab8a3568d96faee8dc2d651832c334..08ac4425b164f0d996bba2c5fc1bf6f2af4165a0 100644 (file)
@@ -235,6 +235,7 @@ dpif_linux_open(const struct dpif_class *class OVS_UNUSED, const char *name,
 {
     struct dpif_linux_dp dp_request, dp;
     struct ofpbuf *buf;
+    uint32_t upcall_pid;
     int error;
 
     error = dpif_linux_init();
@@ -244,7 +245,13 @@ dpif_linux_open(const struct dpif_class *class OVS_UNUSED, const char *name,
 
     /* Create or look up datapath. */
     dpif_linux_dp_init(&dp_request);
-    dp_request.cmd = create ? OVS_DP_CMD_NEW : OVS_DP_CMD_GET;
+    if (create) {
+        dp_request.cmd = OVS_DP_CMD_NEW;
+        upcall_pid = 0;
+        dp_request.upcall_pid = &upcall_pid;
+    } else {
+        dp_request.cmd = OVS_DP_CMD_GET;
+    }
     dp_request.name = name;
     error = dpif_linux_dp_transact(&dp_request, &dp, &buf);
     if (error) {