From: Ben Pfaff Date: Wed, 8 May 2013 20:19:39 +0000 (-0700) Subject: ofproto-dpif: Simplify ofproto_receive(). X-Git-Tag: sliver-openvswitch-1.10.90-3~16^2~9 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3abe1835dbf92fb770d63a9754c77285e3994bd9;p=sliver-openvswitch.git ofproto-dpif: Simplify ofproto_receive(). The tunnel and non-tunnel paths were pretty much the same anyway, so this commit simplifies by merging them. Signed-off-by: Ben Pfaff --- diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index a42625bcc..4d37500b5 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -3921,51 +3921,41 @@ ofproto_receive(const struct dpif_backer *backer, struct ofpbuf *packet, *odp_in_port = flow->in_port; } - if (tnl_port_should_receive(flow)) { - const struct ofport *ofport = tnl_port_receive(flow); - if (!ofport) { - flow->in_port = OFPP_NONE; - goto exit; - } - flow->in_port = ofport->ofp_port; - port = ofport_dpif_cast(ofport); + port = (tnl_port_should_receive(flow) + ? ofport_dpif_cast(tnl_port_receive(flow)) + : odp_port_to_ofport(backer, flow->in_port)); + flow->in_port = port ? port->up.ofp_port : OFPP_NONE; + if (!port) { + goto exit; + } - /* XXX: Since the tunnel module is not scoped per backer, it's - * theoretically possible that we'll receive an ofport belonging to an - * entirely different datapath. In practice, this can't happen because - * no platforms has two separate datapaths which each support - * tunneling. */ - ovs_assert(ofproto_dpif_cast(port->up.ofproto)->backer == backer); - } else { - port = odp_port_to_ofport(backer, flow->in_port); - if (!port) { - flow->in_port = OFPP_NONE; - goto exit; - } + /* XXX: Since the tunnel module is not scoped per backer, for a tunnel port + * it's theoretically possible that we'll receive an ofport belonging to an + * entirely different datapath. In practice, this can't happen because no + * platforms has two separate datapaths which each support tunneling. */ + ovs_assert(ofproto_dpif_cast(port->up.ofproto)->backer == backer); - flow->in_port = port->up.ofp_port; - if (vsp_adjust_flow(ofproto_dpif_cast(port->up.ofproto), flow)) { - if (packet) { - /* Make the packet resemble the flow, so that it gets sent to - * an OpenFlow controller properly, so that it looks correct - * for sFlow, and so that flow_extract() will get the correct - * vlan_tci if it is called on 'packet'. - * - * The allocated space inside 'packet' probably also contains - * 'key', that is, both 'packet' and 'key' are probably part of - * a struct dpif_upcall (see the large comment on that - * structure definition), so pushing data on 'packet' is in - * general not a good idea since it could overwrite 'key' or - * free it as a side effect. However, it's OK in this special - * case because we know that 'packet' is inside a Netlink - * attribute: pushing 4 bytes will just overwrite the 4-byte - * "struct nlattr", which is fine since we don't need that - * header anymore. */ - eth_push_vlan(packet, flow->vlan_tci); - } - /* We can't reproduce 'key' from 'flow'. */ - fitness = fitness == ODP_FIT_PERFECT ? ODP_FIT_TOO_MUCH : fitness; - } + if (vsp_adjust_flow(ofproto_dpif_cast(port->up.ofproto), flow)) { + if (packet) { + /* Make the packet resemble the flow, so that it gets sent to + * an OpenFlow controller properly, so that it looks correct + * for sFlow, and so that flow_extract() will get the correct + * vlan_tci if it is called on 'packet'. + * + * The allocated space inside 'packet' probably also contains + * 'key', that is, both 'packet' and 'key' are probably part of + * a struct dpif_upcall (see the large comment on that + * structure definition), so pushing data on 'packet' is in + * general not a good idea since it could overwrite 'key' or + * free it as a side effect. However, it's OK in this special + * case because we know that 'packet' is inside a Netlink + * attribute: pushing 4 bytes will just overwrite the 4-byte + * "struct nlattr", which is fine since we don't need that + * header anymore. */ + eth_push_vlan(packet, flow->vlan_tci); + } + /* We can't reproduce 'key' from 'flow'. */ + fitness = fitness == ODP_FIT_PERFECT ? ODP_FIT_TOO_MUCH : fitness; } error = 0;