From 40085e569a9ebe849d0a272f433ee745fef75395 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Fri, 2 Aug 2013 14:55:31 -0700 Subject: [PATCH] ofproto-dpif-xlate: Refactor stp_get_port() calls. I had intended to fold this into a previous patch. Signed-off-by: Ethan Jackson Acked-by: Ben Pfaff --- ofproto/ofproto-dpif-xlate.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 91ec01a5a..e728850e5 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -501,25 +501,26 @@ xport_lookup(struct ofport_dpif *ofport) return NULL; } +static struct stp_port * +xport_get_stp_port(const struct xport *xport) +{ + return xport->xbridge->stp && xport->stp_port_no + ? stp_get_port(xport->xbridge->stp, xport->stp_port_no) + : NULL; +} static enum stp_state xport_stp_learn_state(const struct xport *xport) { - enum stp_state stp_state = xport->xbridge->stp && xport->stp_port_no - ? stp_port_get_state(stp_get_port(xport->xbridge->stp, - xport->stp_port_no)) - : STP_DISABLED; - return stp_learn_in_state(stp_state); + struct stp_port *sp = xport_get_stp_port(xport); + return stp_learn_in_state(sp ? stp_port_get_state(sp) : STP_DISABLED); } static bool xport_stp_forward_state(const struct xport *xport) { - enum stp_state stp_state = xport->xbridge->stp && xport->stp_port_no - ? stp_port_get_state(stp_get_port(xport->xbridge->stp, - xport->stp_port_no)) - : STP_DISABLED; - return stp_forward_in_state(stp_state); + struct stp_port *sp = xport_get_stp_port(xport); + return stp_forward_in_state(sp ? stp_port_get_state(sp) : STP_DISABLED); } /* Returns true if STP should process 'flow'. Sets fields in 'wc' that @@ -534,11 +535,9 @@ stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc) static void stp_process_packet(const struct xport *xport, const struct ofpbuf *packet) { + struct stp_port *sp = xport_get_stp_port(xport); struct ofpbuf payload = *packet; struct eth_header *eth = payload.data; - struct stp_port *sp = xport->xbridge->stp && xport->stp_port_no - ? stp_get_port(xport->xbridge->stp, xport->stp_port_no) - : NULL; /* Sink packets on ports that have STP disabled when the bridge has * STP enabled. */ -- 2.47.0