mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
mac-learning: Refactor to increase generality.
In an upcoming commit I want to store a pointer in MAC learning entries in the bridge, instead of an integer port number. The MAC learning library has other clients, and the others do not gracefully fit this new model, so in fact the data will have to become a union. However, this does not fit well with the current mac_learning API, since mac_learning_learn() currently initializes and compares the data. It seems better to break up the API so that only the client has to know the data's format and how to initialize it or compare it. This commit makes this possible. This commit doesn't change the type of the data stored in a MAC learning entry yet. As a side effect this commit has the benefit that clients that don't need gratuitous ARP locking don't have to specify any policy for it at all.
This commit is contained in:
@@ -324,12 +324,15 @@ lswitch_choose_destination(struct lswitch *sw, const struct flow *flow)
|
||||
uint16_t out_port;
|
||||
|
||||
/* Learn the source MAC. */
|
||||
if (sw->ml) {
|
||||
if (mac_learning_learn(sw->ml, flow->dl_src, 0, flow->in_port,
|
||||
GRAT_ARP_LOCK_NONE)) {
|
||||
if (mac_learning_may_learn(sw->ml, flow->dl_src, 0)) {
|
||||
struct mac_entry *mac = mac_learning_insert(sw->ml, flow->dl_src, 0);
|
||||
if (mac_entry_is_new(mac) || mac->port != flow->in_port) {
|
||||
VLOG_DBG_RL(&rl, "%016llx: learned that "ETH_ADDR_FMT" is on "
|
||||
"port %"PRIu16, sw->datapath_id,
|
||||
ETH_ADDR_ARGS(flow->dl_src), flow->in_port);
|
||||
|
||||
mac->port = flow->in_port;
|
||||
mac_learning_changed(sw->ml, mac);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,9 +343,11 @@ lswitch_choose_destination(struct lswitch *sw, const struct flow *flow)
|
||||
|
||||
out_port = OFPP_FLOOD;
|
||||
if (sw->ml) {
|
||||
int learned_port = mac_learning_lookup(sw->ml, flow->dl_dst, 0, NULL);
|
||||
if (learned_port >= 0) {
|
||||
out_port = learned_port;
|
||||
struct mac_entry *mac;
|
||||
|
||||
mac = mac_learning_lookup(sw->ml, flow->dl_dst, 0, NULL);
|
||||
if (mac) {
|
||||
out_port = mac->port;
|
||||
if (out_port == flow->in_port) {
|
||||
/* Don't send a packet back out its input port. */
|
||||
return OFPP_NONE;
|
||||
|
Reference in New Issue
Block a user