From 39db78a0fb8bcf91a6b0e31867018572e2b6dbe9 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 25 Oct 2011 16:54:42 -0700 Subject: [PATCH] odp-util: New function factored out of put_userspace_action(). An upcoming patch to odp-util will add a new user, but this seems like a reasonable change in any case. --- lib/odp-util.c | 22 ++++++++++++++++++++++ lib/odp-util.h | 3 +++ ofproto/ofproto-dpif.c | 9 +-------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/odp-util.c b/lib/odp-util.c index f67816ef..b4ebd792 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -1388,3 +1388,25 @@ odp_flow_key_to_flow(const struct nlattr *key, size_t key_len, return check_expectations(present_attrs, expected_attrs, key, key_len); } + +/* Appends an OVS_ACTION_ATTR_USERSPACE action to 'odp_actions' that specifies + * Netlink PID 'pid'. If 'cookie' is nonnull, adds a userdata attribute whose + * contents contains 'cookie' and returns the offset within 'odp_actions' of + * 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, + struct ofpbuf *odp_actions) +{ + size_t offset; + + offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_USERSPACE); + nl_msg_put_u32(odp_actions, OVS_USERSPACE_ATTR_PID, pid); + if (cookie) { + nl_msg_put_unspec(odp_actions, OVS_USERSPACE_ATTR_USERDATA, + cookie, sizeof *cookie); + } + nl_msg_end_nested(odp_actions, offset); + + return cookie ? odp_actions->size - NLA_ALIGN(sizeof *cookie) : 0; +} diff --git a/lib/odp-util.h b/lib/odp-util.h index 0f4f9e6b..3003f614 100644 --- a/lib/odp-util.h +++ b/lib/odp-util.h @@ -111,4 +111,7 @@ struct user_action_cookie { BUILD_ASSERT_DECL(sizeof(struct user_action_cookie) == 8); +size_t odp_put_userspace_action(uint32_t pid, + const struct user_action_cookie *, + struct ofpbuf *odp_actions); #endif /* odp-util.h */ diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 6f1efc55..8ce2a34a 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -3516,19 +3516,12 @@ put_userspace_action(const struct ofproto_dpif *ofproto, const struct flow *flow, const struct user_action_cookie *cookie) { - size_t offset; uint32_t pid; pid = dpif_port_get_pid(ofproto->dpif, ofp_port_to_odp_port(flow->in_port)); - offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_USERSPACE); - nl_msg_put_u32(odp_actions, OVS_USERSPACE_ATTR_PID, pid); - nl_msg_put_unspec(odp_actions, OVS_USERSPACE_ATTR_USERDATA, - cookie, sizeof *cookie); - nl_msg_end_nested(odp_actions, offset); - - return odp_actions->size - NLA_ALIGN(sizeof *cookie); + return odp_put_userspace_action(pid, cookie, odp_actions); } /* Compose SAMPLE action for sFlow. */ -- 2.30.2