aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2012-05-04 14:56:40 -0700
committerBen Pfaff <blp@nicira.com>2012-05-09 13:28:37 -0700
commit05a5c1310c4850eeb5422c5b93f7f7483981f2d6 (patch)
tree987b59a2e20922c26619cf41678d6bdfcb2dd2b9 /lib
parentabeea3938034a1b13da315e7de3e4519d01822f8 (diff)
odp-util: Change user_action_cookie from struct to union.
An upcoming commit will introduce a new type and a new use for the additional members. It seems cleanest to use a union, rather that using the existing members multiple ways. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/odp-util.c17
-rw-r--r--lib/odp-util.h14
2 files changed, 17 insertions, 14 deletions
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 85c9d1f5..7bfbadeb 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -185,7 +185,7 @@ format_odp_userspace_action(struct ds *ds, const struct nlattr *attr)
if (a[OVS_USERSPACE_ATTR_USERDATA]) {
uint64_t userdata = nl_attr_get_u64(a[OVS_USERSPACE_ATTR_USERDATA]);
- struct user_action_cookie cookie;
+ union user_action_cookie cookie;
memcpy(&cookie, &userdata, sizeof cookie);
@@ -193,8 +193,9 @@ format_odp_userspace_action(struct ds *ds, const struct nlattr *attr)
case USER_ACTION_COOKIE_SFLOW:
ds_put_format(ds, ",sFlow,"
"vid=%"PRIu16",pcp=%"PRIu8",output=%"PRIu32,
- vlan_tci_to_vid(cookie.vlan_tci),
- vlan_tci_to_pcp(cookie.vlan_tci), cookie.output);
+ vlan_tci_to_vid(cookie.sflow.vlan_tci),
+ vlan_tci_to_pcp(cookie.sflow.vlan_tci),
+ cookie.sflow.output);
break;
case USER_ACTION_COOKIE_UNSPEC:
@@ -348,7 +349,7 @@ parse_odp_action(const char *s, const struct shash *port_names,
} else if (sscanf(s, "userspace(pid=%lli,sFlow,vid=%i,"
"pcp=%i,output=%lli)%n",
&pid, &vid, &pcp, &output, &n) > 0 && n > 0) {
- struct user_action_cookie cookie;
+ union user_action_cookie cookie;
uint16_t tci;
tci = vid | (pcp << VLAN_PCP_SHIFT);
@@ -357,14 +358,14 @@ parse_odp_action(const char *s, const struct shash *port_names,
}
cookie.type = USER_ACTION_COOKIE_SFLOW;
- cookie.vlan_tci = htons(tci);
- cookie.output = output;
+ cookie.sflow.vlan_tci = htons(tci);
+ cookie.sflow.output = output;
odp_put_userspace_action(pid, &cookie, actions);
return n;
} else if (sscanf(s, "userspace(pid=%lli,userdata="
"%31[x0123456789abcdefABCDEF])%n", &pid, userdata_s,
&n) > 0 && n > 0) {
- struct user_action_cookie cookie;
+ union user_action_cookie cookie;
uint64_t userdata;
userdata = strtoull(userdata_s, NULL, 0);
@@ -1726,7 +1727,7 @@ odp_key_fitness_to_string(enum odp_key_fitness fitness)
* the start of the cookie. (If 'cookie' is null, then the return value is not
* meaningful.) */
size_t
-odp_put_userspace_action(uint32_t pid, const struct user_action_cookie *cookie,
+odp_put_userspace_action(uint32_t pid, const union user_action_cookie *cookie,
struct ofpbuf *odp_actions)
{
size_t offset;
diff --git a/lib/odp-util.h b/lib/odp-util.h
index cdafbe46..c52e4709 100644
--- a/lib/odp-util.h
+++ b/lib/odp-util.h
@@ -123,18 +123,20 @@ enum user_action_cookie_type {
/* user_action_cookie is passed as argument to OVS_ACTION_ATTR_USERSPACE.
* Since it is passed to kernel as u64, its size has to be 8 bytes. */
-struct user_action_cookie {
+union user_action_cookie {
uint16_t type; /* enum user_action_cookie_type. */
- /* The following members are used only by USER_ACTION_COOKIE_SFLOW. */
- ovs_be16 vlan_tci; /* Destination VLAN TCI. */
- uint32_t output; /* SFL_FLOW_SAMPLE_TYPE 'output' value. */
+ struct {
+ uint16_t type; /* USER_ACTION_COOKIE_SFLOW. */
+ ovs_be16 vlan_tci; /* Destination VLAN TCI. */
+ uint32_t output; /* SFL_FLOW_SAMPLE_TYPE 'output' value. */
+ } sflow;
};
-BUILD_ASSERT_DECL(sizeof(struct user_action_cookie) == 8);
+BUILD_ASSERT_DECL(sizeof(union user_action_cookie) == 8);
size_t odp_put_userspace_action(uint32_t pid,
- const struct user_action_cookie *,
+ const union user_action_cookie *,
struct ofpbuf *odp_actions);
void commit_odp_actions(const struct flow *, struct flow *base,