datapath: Change userspace vport interface to use Netlink attributes.
[sliver-openvswitch.git] / datapath / vport-patch.c
index 1c32c5a..7dfea6b 100644 (file)
@@ -85,14 +85,31 @@ static void patch_exit(void)
        kfree(peer_table);
 }
 
-static int patch_set_config(struct vport *vport, const void *config, 
+static const struct nla_policy patch_policy[ODP_PATCH_ATTR_MAX + 1] = {
+#ifdef HAVE_NLA_NUL_STRING
+       [ODP_PATCH_ATTR_PEER] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 },
+#endif
+};
+
+static int patch_set_config(struct vport *vport, const struct nlattr *options,
                            struct patch_config *patchconf)
 {
        struct patch_vport *patch_vport = patch_vport_priv(vport);
-       char peer_name[IFNAMSIZ];
+       struct nlattr *a[ODP_PATCH_ATTR_MAX + 1];
+       const char *peer_name;
+       int err;
+
+       if (!options)
+               return -EINVAL;
 
-       strlcpy(peer_name, config, IFNAMSIZ);
+       err = nla_parse_nested(a, ODP_PATCH_ATTR_MAX, options, patch_policy);
+       if (err)
+               return err;
+
+       if (!a[ODP_PATCH_ATTR_PEER] || VERIFY_NUL_STRING(a[ODP_PATCH_ATTR_PEER], IFNAMSIZ - 1))
+               return -EINVAL;
 
+       peer_name = nla_data(a[ODP_PATCH_ATTR_PEER]);
        if (!strcmp(patch_vport->name, peer_name))
                return -EINVAL;
 
@@ -125,7 +142,7 @@ static struct vport *patch_create(const struct vport_parms *parms)
                goto error_free_vport;
        }
 
-       err = patch_set_config(vport, parms->config, patchconf);
+       err = patch_set_config(vport, parms->options, patchconf);
        if (err)
                goto error_free_patchconf;
 
@@ -152,7 +169,27 @@ error:
        return ERR_PTR(err);
 }
 
-static int patch_modify(struct vport *vport, struct odp_port *port)
+static void free_port_rcu(struct rcu_head *rcu)
+{
+       struct patch_vport *patch_vport = container_of(rcu,
+                                         struct patch_vport, rcu);
+
+       kfree((struct patch_config __force *)patch_vport->patchconf);
+       vport_free(vport_from_priv(patch_vport));
+}
+
+static int patch_destroy(struct vport *vport)
+{
+       struct patch_vport *patch_vport = patch_vport_priv(vport);
+
+       update_peers(patch_vport->name, NULL);
+       hlist_del(&patch_vport->hash_node);
+       call_rcu(&patch_vport->rcu, free_port_rcu);
+
+       return 0;
+}
+
+static int patch_set_options(struct vport *vport, struct nlattr *options)
 {
        struct patch_vport *patch_vport = patch_vport_priv(vport);
        struct patch_config *patchconf;
@@ -165,12 +202,12 @@ static int patch_modify(struct vport *vport, struct odp_port *port)
                goto error;
        }
 
-       err = patch_set_config(vport, port->config, patchconf);
+       err = patch_set_config(vport, options, patchconf);
        if (err)
                goto error_free;
 
        assign_config_rcu(vport, patchconf);
-       
+
        hlist_del(&patch_vport->hash_node);
 
        rcu_assign_pointer(patch_vport->peer, vport_locate(patchconf->peer_name));
@@ -184,26 +221,6 @@ error:
        return err;
 }
 
-static void free_port_rcu(struct rcu_head *rcu)
-{
-       struct patch_vport *patch_vport = container_of(rcu,
-                                         struct patch_vport, rcu);
-
-       kfree((struct patch_config __force *)patch_vport->patchconf);
-       vport_free(vport_from_priv(patch_vport));
-}
-
-static int patch_destroy(struct vport *vport)
-{
-       struct patch_vport *patch_vport = patch_vport_priv(vport);
-
-       update_peers(patch_vport->name, NULL);
-       hlist_del(&patch_vport->hash_node);
-       call_rcu(&patch_vport->rcu, free_port_rcu);
-
-       return 0;
-}
-
 static void update_peers(const char *name, struct vport *vport)
 {
        struct hlist_head *bucket = hash_bucket(name);
@@ -264,13 +281,12 @@ static const unsigned char *patch_get_addr(const struct vport *vport)
        return rcu_dereference_rtnl(patch_vport->patchconf)->eth_addr;
 }
 
-static void patch_get_config(const struct vport *vport, void *config)
+static int patch_get_options(const struct vport *vport, struct sk_buff *skb)
 {
-       const struct patch_vport *patch_vport = patch_vport_priv(vport);
-       const char *peer_name;
+       struct patch_vport *patch_vport = patch_vport_priv(vport);
+       struct patch_config *patchconf = rcu_dereference_rtnl(patch_vport->patchconf);
 
-       peer_name = rcu_dereference_rtnl(patch_vport->patchconf)->peer_name;
-       strlcpy(config, peer_name, VPORT_CONFIG_SIZE);
+       return nla_put_string(skb, ODP_PATCH_ATTR_PEER, patchconf->peer_name);
 }
 
 static int patch_get_mtu(const struct vport *vport)
@@ -302,13 +318,13 @@ const struct vport_ops patch_vport_ops = {
        .init           = patch_init,
        .exit           = patch_exit,
        .create         = patch_create,
-       .modify         = patch_modify,
        .destroy        = patch_destroy,
        .set_mtu        = patch_set_mtu,
        .set_addr       = patch_set_addr,
        .get_name       = patch_get_name,
        .get_addr       = patch_get_addr,
-       .get_config     = patch_get_config,
+       .get_options    = patch_get_options,
+       .set_options    = patch_set_options,
        .get_dev_flags  = vport_gen_get_dev_flags,
        .is_running     = vport_gen_is_running,
        .get_operstate  = vport_gen_get_operstate,