From f8826ef578229bc910b339ce9e578825f95a7380 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Mon, 13 Apr 2009 17:41:33 -0700 Subject: [PATCH] Add support for explicitly specifying a "drop" action when adding a flow. When adding a flow entry with dpctl, the user specifies a set of actions to execute when a match occurs. If none are specified, then the packet is implicitly dropped by OpenFlow. When dumping these flows, the output of dpctl shows an action of "drop". However, dpctl did not support adding a flow with an explicit "drop" action. This fixes that lack of symmetry. --- utilities/dpctl.8.in | 4 ++++ utilities/dpctl.c | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/utilities/dpctl.8.in b/utilities/dpctl.8.in index 4ddc48a9..f3b33403 100644 --- a/utilities/dpctl.8.in +++ b/utilities/dpctl.8.in @@ -434,6 +434,10 @@ Outputs the packet on the ``local port,'' which corresponds to the \fBof\fIn\fR network device (see \fBCONTACTING THE CONTROLLER\fR in \fBsecchan\fR(8) for information on the \fBof\fIn\fR network device). +.IP \fBdrop\fR +Discards the packet, so no further processing or forwarding takes place. +If a drop action is used, no other actions may be specified. + .IP \fBmod_vlan_vid\fR:\fIvlan_vid\fR Modifies the VLAN id on a packet. The VLAN tag is added or modified as necessary to match the value specified. If the VLAN tag is added, diff --git a/utilities/dpctl.c b/utilities/dpctl.c index 6d334e2a..26e5160d 100644 --- a/utilities/dpctl.c +++ b/utilities/dpctl.c @@ -912,12 +912,17 @@ str_to_action(char *str, struct ofpbuf *b) { char *act, *arg; char *saveptr = NULL; + bool drop = false; for (act = strtok_r(str, ", \t\r\n", &saveptr); act; act = strtok_r(NULL, ", \t\r\n", &saveptr)) { uint16_t port; + if (drop) { + ofp_fatal(0, "Drop actions must not be followed by other actions"); + } + /* Arguments are separated by colons */ arg = strchr(act, ':'); if (arg) { @@ -943,6 +948,10 @@ str_to_action(char *str, struct ofpbuf *b) put_dl_addr_action(b, OFPAT_SET_DL_DST, arg); } else if (!strcasecmp(act, "output")) { put_output_action(b, str_to_u32(arg)); + } else if (!strcasecmp(act, "drop")) { + /* A drop action in OpenFlow occurs by just not setting + * an action. */ + drop=true; #ifdef SUPPORT_SNAT } else if (!strcasecmp(act, "nat")) { struct nx_action_snat *sa; -- 2.30.2