+
+int ofputil_decode_action(const union ofp_action *);
+enum ofputil_action_code ofputil_decode_action_unsafe(
+ const union ofp_action *);
+
+int ofputil_action_code_from_name(const char *);
+
+void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
+
+/* For each OpenFlow action <ENUM> that has a corresponding action structure
+ * struct <STRUCT>, this defines two functions:
+ *
+ * void ofputil_init_<ENUM>(struct <STRUCT> *action);
+ *
+ * Initializes the parts of 'action' that identify it as having type <ENUM>
+ * and length 'sizeof *action' and zeros the rest. For actions that have
+ * variable length, the length used and cleared is that of struct <STRUCT>.
+ *
+ * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
+ *
+ * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
+ * initializes it with ofputil_init_<ENUM>(), and returns it.
+ */
+#define OFPAT_ACTION(ENUM, STRUCT, NAME) \
+ void ofputil_init_##ENUM(struct STRUCT *); \
+ struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
+#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
+ void ofputil_init_##ENUM(struct STRUCT *); \
+ struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
+#include "ofp-util.def"
+
+#define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
+
+static inline union ofp_action *
+ofputil_action_next(const union ofp_action *a)
+{
+ return ((union ofp_action *) (void *)
+ ((uint8_t *) a + ntohs(a->header.len)));
+}
+
+static inline bool
+ofputil_action_is_valid(const union ofp_action *a, size_t n_actions)
+{
+ uint16_t len = ntohs(a->header.len);
+ return (!(len % OFP_ACTION_ALIGN)
+ && len >= sizeof *a
+ && len / sizeof *a <= n_actions);
+}
+
+/* This macro is careful to check for actions with bad lengths. */
+#define OFPUTIL_ACTION_FOR_EACH(ITER, LEFT, ACTIONS, N_ACTIONS) \
+ for ((ITER) = (ACTIONS), (LEFT) = (N_ACTIONS); \
+ (LEFT) > 0 && ofputil_action_is_valid(ITER, LEFT); \
+ ((LEFT) -= ntohs((ITER)->header.len) / sizeof(union ofp_action), \
+ (ITER) = ofputil_action_next(ITER)))
+
+/* This macro does not check for actions with bad lengths. It should only be
+ * used with actions from trusted sources or with actions that have already
+ * been validated (e.g. with OFPUTIL_ACTION_FOR_EACH). */
+#define OFPUTIL_ACTION_FOR_EACH_UNSAFE(ITER, LEFT, ACTIONS, N_ACTIONS) \
+ for ((ITER) = (ACTIONS), (LEFT) = (N_ACTIONS); \
+ (LEFT) > 0; \
+ ((LEFT) -= ntohs((ITER)->header.len) / sizeof(union ofp_action), \
+ (ITER) = ofputil_action_next(ITER)))