static int validate_actions(const struct nlattr *actions, u32 actions_len)
{
- const struct nlattr *a;
- int rem;
-
- nla_for_each_attr(a, actions, actions_len, rem) {
- static const u32 action_lens[ODPAT_MAX + 1] = {
- [ODPAT_OUTPUT] = 4,
- [ODPAT_CONTROLLER] = 8,
- [ODPAT_SET_DL_TCI] = 2,
- [ODPAT_STRIP_VLAN] = 0,
- [ODPAT_SET_DL_SRC] = ETH_ALEN,
- [ODPAT_SET_DL_DST] = ETH_ALEN,
- [ODPAT_SET_NW_SRC] = 4,
- [ODPAT_SET_NW_DST] = 4,
- [ODPAT_SET_NW_TOS] = 1,
- [ODPAT_SET_TP_SRC] = 2,
- [ODPAT_SET_TP_DST] = 2,
- [ODPAT_SET_TUNNEL] = 8,
- [ODPAT_SET_PRIORITY] = 4,
- [ODPAT_POP_PRIORITY] = 0,
- [ODPAT_DROP_SPOOFED_ARP] = 0,
- };
- int type = nla_type(a);
-
- if (type > ODPAT_MAX || nla_len(a) != action_lens[type])
- return -EINVAL;
-
- switch (type) {
+ const struct nlattr *a;
+ int rem;
+
+ nla_for_each_attr(a, actions, actions_len, rem) {
+ static const u32 action_lens[ODPAT_MAX + 1] = {
+ [ODPAT_OUTPUT] = 4,
+ [ODPAT_CONTROLLER] = 8,
+ [ODPAT_SET_DL_TCI] = 2,
+ [ODPAT_STRIP_VLAN] = 0,
+ [ODPAT_SET_DL_SRC] = ETH_ALEN,
+ [ODPAT_SET_DL_DST] = ETH_ALEN,
+ [ODPAT_SET_NW_SRC] = 4,
+ [ODPAT_SET_NW_DST] = 4,
+ [ODPAT_SET_NW_TOS] = 1,
+ [ODPAT_SET_TP_SRC] = 2,
+ [ODPAT_SET_TP_DST] = 2,
+ [ODPAT_SET_TUNNEL] = 8,
+ [ODPAT_SET_PRIORITY] = 4,
+ [ODPAT_POP_PRIORITY] = 0,
+ [ODPAT_DROP_SPOOFED_ARP] = 0,
+ };
+ int type = nla_type(a);
+
+ if (type > ODPAT_MAX || nla_len(a) != action_lens[type])
+ return -EINVAL;
+
+ switch (type) {
case ODPAT_UNSPEC:
return -EINVAL;
- case ODPAT_CONTROLLER:
- case ODPAT_STRIP_VLAN:
- case ODPAT_SET_DL_SRC:
- case ODPAT_SET_DL_DST:
- case ODPAT_SET_NW_SRC:
- case ODPAT_SET_NW_DST:
- case ODPAT_SET_TP_SRC:
- case ODPAT_SET_TP_DST:
- case ODPAT_SET_TUNNEL:
- case ODPAT_SET_PRIORITY:
- case ODPAT_POP_PRIORITY:
- case ODPAT_DROP_SPOOFED_ARP:
- /* No validation needed. */
- break;
-
- case ODPAT_OUTPUT:
- if (nla_get_u32(a) >= DP_MAX_PORTS)
- return -EINVAL;
+ case ODPAT_CONTROLLER:
+ case ODPAT_STRIP_VLAN:
+ case ODPAT_SET_DL_SRC:
+ case ODPAT_SET_DL_DST:
+ case ODPAT_SET_NW_SRC:
+ case ODPAT_SET_NW_DST:
+ case ODPAT_SET_TP_SRC:
+ case ODPAT_SET_TP_DST:
+ case ODPAT_SET_TUNNEL:
+ case ODPAT_SET_PRIORITY:
+ case ODPAT_POP_PRIORITY:
+ case ODPAT_DROP_SPOOFED_ARP:
+ /* No validation needed. */
+ break;
+
+ case ODPAT_OUTPUT:
+ if (nla_get_u32(a) >= DP_MAX_PORTS)
+ return -EINVAL;
break;
- case ODPAT_SET_DL_TCI:
+ case ODPAT_SET_DL_TCI:
if (nla_get_be16(a) & htons(VLAN_CFI_MASK))
return -EINVAL;
- break;
+ break;
- case ODPAT_SET_NW_TOS:
- if (nla_get_u8(a) & INET_ECN_MASK)
- return -EINVAL;
- break;
+ case ODPAT_SET_NW_TOS:
+ if (nla_get_u8(a) & INET_ECN_MASK)
+ return -EINVAL;
+ break;
- default:
- return -EOPNOTSUPP;
- }
- }
+ default:
+ return -EOPNOTSUPP;
+ }
+ }
- if (rem > 0)
- return -EINVAL;
+ if (rem > 0)
+ return -EINVAL;
- return 0;
+ return 0;
}
static struct sw_flow_actions *get_actions(const struct odp_flow *flow)
return flowvec->n_flows;
}
-struct list_flows_cbdata {
- struct datapath *dp;
- struct odp_flow __user *uflows;
- u32 n_flows;
- u32 listed_flows;
-};
-
-static int list_flow(struct tbl_node *node, void *cbdata_)
-{
- struct sw_flow *flow = flow_cast(node);
- struct list_flows_cbdata *cbdata = cbdata_;
- struct odp_flow __user *ufp = &cbdata->uflows[cbdata->listed_flows++];
- int error;
-
- if (copy_to_user(&ufp->key, &flow->key, sizeof(flow->key)))
- return -EFAULT;
- error = answer_query(cbdata->dp, flow, 0, ufp);
- if (error)
- return error;
-
- if (cbdata->listed_flows >= cbdata->n_flows)
- return cbdata->listed_flows;
- return 0;
-}
-
-static int do_list_flows(struct datapath *dp, const struct odp_flowvec *flowvec)
-{
- struct list_flows_cbdata cbdata;
- int error;
-
- if (!flowvec->n_flows)
- return 0;
-
- cbdata.dp = dp;
- cbdata.uflows = (struct odp_flow __user __force*)flowvec->flows;
- cbdata.n_flows = flowvec->n_flows;
- cbdata.listed_flows = 0;
-
- error = tbl_foreach(get_table_protected(dp), list_flow, &cbdata);
- return error ? error : cbdata.listed_flows;
-}
-
static int do_flowvec_ioctl(struct datapath *dp, unsigned long argp,
int (*function)(struct datapath *,
const struct odp_flowvec *))
: put_user(retval, &uflowvec->n_flows));
}
+static struct sw_flow *do_dump_flow(struct datapath *dp, u32 __user *state)
+{
+ struct tbl *table = get_table_protected(dp);
+ struct tbl_node *tbl_node;
+ u32 bucket, obj;
+
+ if (get_user(bucket, &state[0]) || get_user(obj, &state[1]))
+ return ERR_PTR(-EFAULT);
+
+ tbl_node = tbl_next(table, &bucket, &obj);
+
+ if (put_user(bucket, &state[0]) || put_user(obj, &state[1]))
+ return ERR_PTR(-EFAULT);
+
+ return tbl_node ? flow_cast(tbl_node) : NULL;
+}
+
+static int dump_flow(struct datapath *dp, struct odp_flow_dump __user *udumpp)
+{
+ struct odp_flow __user *uflowp;
+ struct sw_flow *flow;
+
+ flow = do_dump_flow(dp, udumpp->state);
+ if (IS_ERR(flow))
+ return PTR_ERR(flow);
+
+ if (get_user(uflowp, (struct odp_flow __user *__user*)&udumpp->flow))
+ return -EFAULT;
+
+ if (!flow)
+ return put_user(ODPFF_EOF, &uflowp->flags);
+
+ if (copy_to_user(&uflowp->key, &flow->key, sizeof(struct odp_flow_key)) ||
+ put_user(0, &uflowp->flags))
+ return -EFAULT;
+ return answer_query(dp, flow, 0, uflowp);
+}
+
static int do_execute(struct datapath *dp, const struct odp_execute *execute)
{
struct odp_flow_key key;
err = do_flowvec_ioctl(dp, argp, do_query_flows);
break;
- case ODP_FLOW_LIST:
- err = do_flowvec_ioctl(dp, argp, do_list_flows);
+ case ODP_FLOW_DUMP:
+ err = dump_flow(dp, (struct odp_flow_dump __user *)argp);
break;
case ODP_EXECUTE:
return n_flows;
}
-struct compat_list_flows_cbdata {
- struct datapath *dp;
- struct compat_odp_flow __user *uflows;
- u32 n_flows;
- u32 listed_flows;
-};
-
-static int compat_list_flow(struct tbl_node *node, void *cbdata_)
+static int compat_dump_flow(struct datapath *dp, struct compat_odp_flow_dump __user *udumpp)
{
- struct sw_flow *flow = flow_cast(node);
- struct compat_list_flows_cbdata *cbdata = cbdata_;
- struct compat_odp_flow __user *ufp = &cbdata->uflows[cbdata->listed_flows++];
- int error;
-
- if (copy_to_user(&ufp->key, &flow->key, sizeof(flow->key)))
- return -EFAULT;
- error = compat_answer_query(cbdata->dp, flow, 0, ufp);
- if (error)
- return error;
-
- if (cbdata->listed_flows >= cbdata->n_flows)
- return cbdata->listed_flows;
- return 0;
-}
+ struct compat_odp_flow __user *uflowp;
+ compat_uptr_t compat_ufp;
+ struct sw_flow *flow;
-static int compat_list_flows(struct datapath *dp,
- struct compat_odp_flow __user *flows, u32 n_flows)
-{
- struct compat_list_flows_cbdata cbdata;
- int error;
+ flow = do_dump_flow(dp, udumpp->state);
+ if (IS_ERR(flow))
+ return PTR_ERR(flow);
- if (!n_flows)
- return 0;
+ if (get_user(compat_ufp, &udumpp->flow))
+ return -EFAULT;
+ uflowp = compat_ptr(compat_ufp);
- cbdata.dp = dp;
- cbdata.uflows = flows;
- cbdata.n_flows = n_flows;
- cbdata.listed_flows = 0;
+ if (!flow)
+ return put_user(ODPFF_EOF, &uflowp->flags);
- error = tbl_foreach(get_table_protected(dp), compat_list_flow, &cbdata);
- return error ? error : cbdata.listed_flows;
+ if (copy_to_user(&uflowp->key, &flow->key, sizeof(struct odp_flow_key)) ||
+ put_user(0, &uflowp->flags))
+ return -EFAULT;
+ return compat_answer_query(dp, flow, 0, uflowp);
}
static int compat_flowvec_ioctl(struct datapath *dp, unsigned long argp,
err = compat_flowvec_ioctl(dp, argp, compat_query_flows);
break;
- case ODP_FLOW_LIST32:
- err = compat_flowvec_ioctl(dp, argp, compat_list_flows);
+ case ODP_FLOW_DUMP32:
+ err = compat_dump_flow(dp, compat_ptr(argp));
break;
case ODP_EXECUTE32: