[ovs-dev] [PATCH 4/6] nx-match: New function nxm_src_check().
Ben Pfaff
blp at nicira.com
Thu Aug 11 16:19:35 UTC 2011
On Wed, Aug 10, 2011 at 05:21:41PM -0700, Ethan Jackson wrote:
> This patch also updates nxm_check_reg_move() to use nxm_src_check()
> and nxm_dst_check(). A user outside of nxm-match will be added in
> a future patch.
I have a similar patch in the branch that I'm working on, too. The
only important difference is that I didn't change
nxm_check_reg_move(), because nxm_encode_ofs_nbits() loses
information: it will fail to signal an error and return a nonsensical
result if ofs >= 1024 or n_bits > 64.
Arguably nxm_src_check() and nxm_dst_check() should take separate ofs
and nbits parameters. They don't, if I recall correctly, only because
that was convenient for the first few callers.
Here's my version.
--8<--------------------------cut here-------------------------->8--
From: Ben Pfaff <blp at nicira.com>
Date: Thu, 11 Aug 2011 09:17:54 -0700
Subject: [PATCH] nx-match: New function nxm_src_check().
---
lib/nx-match.c | 28 +++++++++++++++++++++++++++-
lib/nx-match.h | 3 ++-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/lib/nx-match.c b/lib/nx-match.c
index e698cc6..68542cf 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -1211,8 +1211,34 @@ nxm_check_reg_move(const struct nx_action_reg_move *action,
return 0;
}
+/* Given a flow, checks that the source field represented by 'src_header' and
+ * 'ofs_nbits' is valid. Returns 0 if successful, otherwise a positive
+ * OpenFlow error code constructed with ofp_mkerr(). */
+int
+nxm_src_check(ovs_be32 src_header, ovs_be16 ofs_nbits, const struct flow *flow)
+{
+ const struct nxm_field *src;
+ int ofs, n_bits;
+
+ ofs = nxm_decode_ofs(ofs_nbits);
+ n_bits = nxm_decode_n_bits(ofs_nbits);
+ src = nxm_field_lookup(ntohl(src_header));
+
+ if (!field_ok(src, flow, ofs + n_bits)) {
+ VLOG_WARN_RL(&rl, "invalid field");
+ return BAD_ARGUMENT;
+ }
+
+ return 0;
+}
+
/* Given a flow, checks that the destination field represented by 'dst_header'
- * and 'ofs_nbits' is valid and large enough for 'min_n_bits' bits of data. */
+ * and 'ofs_nbits' is valid. Also checks that the 'n_bits' inside 'ofs_nbits'
+ * is at least 'min_n_bits' bits wide (which doesn't have to happen here but is
+ * convenient for some of the callers).
+ *
+ * Returns 0 if successful, otherwise a positive OpenFlow error code
+ * constructed with ofp_mkerr(). */
int
nxm_dst_check(ovs_be32 dst_header, ovs_be16 ofs_nbits, size_t min_n_bits,
const struct flow *flow)
diff --git a/lib/nx-match.h b/lib/nx-match.h
index 5365cca..29dbd53 100644
--- a/lib/nx-match.h
+++ b/lib/nx-match.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Nicira Networks.
+ * Copyright (c) 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@ void nxm_format_reg_load(const struct nx_action_reg_load *, struct ds *);
int nxm_check_reg_move(const struct nx_action_reg_move *, const struct flow *);
int nxm_check_reg_load(const struct nx_action_reg_load *, const struct flow *);
+int nxm_src_check(ovs_be32 src, ovs_be16 ofs_nbits, const struct flow *);
int nxm_dst_check(ovs_be32 dst, ovs_be16 ofs_nbits, size_t min_n_bits,
const struct flow *);
--
1.7.4.4
More information about the dev
mailing list