From 1648ddd7c18dab974efae3a007591b6479e3c053 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 22 Mar 2011 09:57:06 -0700 Subject: [PATCH] bridge: Use pointer to "struct port", not "port_idx", for MAC learning. This takes a step toward changing the data structure used for keeping track of ports from an array to a more appropriate data structure. --- lib/mac-learning.h | 1 + vswitchd/bridge.c | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/mac-learning.h b/lib/mac-learning.h index 2bff4656..4930d0bb 100644 --- a/lib/mac-learning.h +++ b/lib/mac-learning.h @@ -48,6 +48,7 @@ struct mac_entry { /* Learned port. */ union { + void *p; int i; } port; }; diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index cdce56ba..c7559c52 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -1517,11 +1517,9 @@ bridge_unixctl_fdb_show(struct unixctl_conn *conn, ds_put_cstr(&ds, " port VLAN MAC Age\n"); LIST_FOR_EACH (e, lru_node, &br->ml->lrus) { - if (e->port.i < 0 || e->port.i >= br->n_ports) { - continue; - } + struct port *port = e->port.p; ds_put_format(&ds, "%5d %4d "ETH_ADDR_FMT" %3d\n", - port_get_an_iface(br->ports[e->port.i])->dp_ifidx, + port_get_an_iface(port)->dp_ifidx, e->vlan, ETH_ADDR_ARGS(e->mac), mac_entry_age(e)); } unixctl_command_reply(conn, 200, ds_cstr(&ds)); @@ -2787,7 +2785,7 @@ update_learning_table(struct bridge *br, const struct flow *flow, int vlan, } } - if (mac_entry_is_new(mac) || mac->port.i != in_port->port_idx) { + if (mac_entry_is_new(mac) || mac->port.p != in_port) { /* The log messages here could actually be useful in debugging, * so keep the rate limit relatively high. */ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300); @@ -2796,7 +2794,7 @@ update_learning_table(struct bridge *br, const struct flow *flow, int vlan, br->name, ETH_ADDR_ARGS(flow->dl_src), in_port->name, vlan); - mac->port.i = in_port->port_idx; + mac->port.p = in_port; ofproto_revalidate(br->ofproto, mac_learning_changed(br->ml, mac)); } } @@ -2902,7 +2900,7 @@ is_admissible(struct bridge *br, const struct flow *flow, bool have_packet, * reflections on bond slaves. If this is the case, just drop the * packet now. */ mac = mac_learning_lookup(br->ml, flow->dl_src, vlan, NULL); - if (mac && mac->port.i != in_port->port_idx && + if (mac && mac->port.p != in_port && (!is_gratuitous_arp(flow) || mac_entry_is_grat_arp_locked(mac))) { return false; } @@ -2937,8 +2935,8 @@ process_flow(struct bridge *br, const struct flow *flow, /* Determine output port. */ mac = mac_learning_lookup(br->ml, flow->dl_dst, vlan, tags); - if (mac && mac->port.i >= 0 && mac->port.i < br->n_ports) { - out_port = br->ports[mac->port.i]; + if (mac) { + mac = mac->port.p; } else if (!packet && !eth_addr_is_multicast(flow->dl_dst)) { /* If we are revalidating but don't have a learning entry then * eject the flow. Installing a flow that floods packets opens @@ -3425,7 +3423,7 @@ bond_send_learning_packets(struct port *port) struct flow flow; int retval; - if (e->port.i == port->port_idx) { + if (e->port.p == port) { continue; } @@ -3601,7 +3599,7 @@ bond_unixctl_show(struct unixctl_conn *conn, memcpy(flow.dl_src, me->mac, ETH_ADDR_LEN); if (bond_hash_src(me->mac, me->vlan) == hash - && me->port.i != port->port_idx + && me->port.p != port && choose_output_iface(port, &flow, me->vlan, &dp_ifidx, &tags) && dp_ifidx == iface->dp_ifidx) -- 2.30.2