[ovs-dev] [PATCH RFC 1/5] ofproto: Refactor handle_port_mod() by extracting validity check
Alexandru Copot
alex.mihai.c at gmail.com
Tue May 6 18:28:27 UTC 2014
This will be later used by OF1.4 bundles to check added messages.
Signed-off-by: Alexandru Copot <alex.mihai.c at gmail.com>
Cc: Daniel Baluta <dbaluta at ixiacom.com>
---
ofproto/ofproto.c | 33 +++++++++++++++++++++++----------
ofproto/ofproto.h | 5 +++++
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index d92bafd..cf3f271 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -3025,36 +3025,49 @@ update_port_config(struct ofconn *ofconn, struct ofport *port,
}
}
-static enum ofperr
-handle_port_mod(struct ofconn *ofconn, const struct ofp_header *oh)
+enum ofperr
+check_port_mod(struct ofconn *ofconn, const struct ofp_header *oh,
+ struct ofputil_port_mod *pm, struct ofport **port)
{
struct ofproto *p = ofconn_get_ofproto(ofconn);
- struct ofputil_port_mod pm;
- struct ofport *port;
enum ofperr error;
+ *port = NULL;
error = reject_slave_controller(ofconn);
if (error) {
return error;
}
- error = ofputil_decode_port_mod(oh, &pm);
+ error = ofputil_decode_port_mod(oh, pm);
if (error) {
return error;
}
- port = ofproto_get_port(p, pm.port_no);
- if (!port) {
+ *port = ofproto_get_port(p, pm->port_no);
+ if (!*port) {
return OFPERR_OFPPMFC_BAD_PORT;
- } else if (!eth_addr_equals(port->pp.hw_addr, pm.hw_addr)) {
+ } else if (!eth_addr_equals((*port)->pp.hw_addr, pm->hw_addr)) {
return OFPERR_OFPPMFC_BAD_HW_ADDR;
- } else {
+ }
+
+ return 0;
+}
+
+static enum ofperr
+handle_port_mod(struct ofconn *ofconn, const struct ofp_header *oh)
+{
+ struct ofputil_port_mod pm;
+ struct ofport *port;
+ enum ofperr error;
+
+ error = check_port_mod(ofconn, oh, &pm, &port);
+ if (!error) {
update_port_config(ofconn, port, pm.config, pm.mask);
if (pm.advertise) {
netdev_set_advertisements(port->netdev, pm.advertise);
}
}
- return 0;
+ return error;
}
static enum ofperr
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index 9ba6354..60cbdd1 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -44,6 +44,11 @@ struct ofproto;
struct shash;
struct simap;
struct smap;
+struct ofconn;
+
+enum ofperr
+check_port_mod(struct ofconn *ofconn, const struct ofp_header *oh,
+ struct ofputil_port_mod *pm, struct ofport **port);
struct ofproto_controller_info {
bool is_connected;
--
1.9.2
More information about the dev
mailing list