36
38
* relearning based on a reflection from a bond slave. */
37
39
#define MAC_GRAT_ARP_LOCK_TIME 5
39
/* A MAC learning table entry. */
41
/* A MAC learning table entry.
42
* Guarded by owning 'mac_learning''s rwlock */
41
44
struct hmap_node hmap_node; /* Node in a mac_learning hmap. */
42
struct list lru_node; /* Element in 'lrus' list. */
43
45
time_t expires; /* Expiration time. */
44
46
time_t grat_arp_lock; /* Gratuitous ARP lock expiration time. */
45
47
uint8_t mac[ETH_ADDR_LEN]; /* Known MAC address. */
46
48
uint16_t vlan; /* VLAN tag. */
47
49
tag_type tag; /* Tag for this learning entry. */
51
/* The following are marked guarded to prevent users from iterating over or
52
* accessing a mac_entry without hodling the parent mac_learning rwlock. */
53
struct list lru_node OVS_GUARDED; /* Element in 'lrus' list. */
49
55
/* Learned port. */
56
int mac_entry_age(const struct mac_learning *, const struct mac_entry *);
58
62
/* Returns true if mac_learning_insert() just created 'mac' and the caller has
59
63
* not yet properly initialized it. */
60
64
static inline bool mac_entry_is_new(const struct mac_entry *mac)
79
83
/* MAC learning table. */
80
84
struct mac_learning {
81
85
struct hmap table; /* Learning table. */
82
struct list lrus; /* In-use entries, least recently used at the
83
front, most recently used at the back. */
86
struct list lrus OVS_GUARDED; /* In-use entries, least recently used at the
87
front, most recently used at the back. */
84
88
uint32_t secret; /* Secret for randomizing hash table. */
85
89
unsigned long *flood_vlans; /* Bitmap of learning disabled VLANs. */
86
90
unsigned int idle_time; /* Max age before deleting an entry. */
87
91
size_t max_entries; /* Max number of learned MACs. */
92
struct tag_set tags; /* Tags which have changed. */
94
struct ovs_rwlock rwlock;
97
int mac_entry_age(const struct mac_learning *ml, const struct mac_entry *e)
98
OVS_REQ_RDLOCK(ml->rwlock);
91
101
struct mac_learning *mac_learning_create(unsigned int idle_time);
92
void mac_learning_destroy(struct mac_learning *);
102
struct mac_learning *mac_learning_ref(const struct mac_learning *);
103
void mac_learning_unref(struct mac_learning *);
94
void mac_learning_run(struct mac_learning *, struct tag_set *);
95
void mac_learning_wait(struct mac_learning *);
105
void mac_learning_run(struct mac_learning *ml, struct tag_set *)
106
OVS_REQ_WRLOCK(ml->rwlock);
107
void mac_learning_wait(struct mac_learning *ml)
108
OVS_REQ_RDLOCK(ml->rwlock);
97
110
/* Configuration. */
98
bool mac_learning_set_flood_vlans(struct mac_learning *,
99
const unsigned long *bitmap);
100
void mac_learning_set_idle_time(struct mac_learning *, unsigned int idle_time);
101
void mac_learning_set_max_entries(struct mac_learning *, size_t max_entries);
111
bool mac_learning_set_flood_vlans(struct mac_learning *ml,
112
const unsigned long *bitmap)
113
OVS_REQ_WRLOCK(ml->rwlock);
114
void mac_learning_set_idle_time(struct mac_learning *ml,
115
unsigned int idle_time)
116
OVS_REQ_WRLOCK(ml->rwlock);
117
void mac_learning_set_max_entries(struct mac_learning *ml, size_t max_entries)
118
OVS_REQ_WRLOCK(ml->rwlock);
104
bool mac_learning_may_learn(const struct mac_learning *,
121
bool mac_learning_may_learn(const struct mac_learning *ml,
105
122
const uint8_t src_mac[ETH_ADDR_LEN],
107
struct mac_entry *mac_learning_insert(struct mac_learning *,
124
OVS_REQ_RDLOCK(ml->rwlock);
125
struct mac_entry *mac_learning_insert(struct mac_learning *ml,
108
126
const uint8_t src[ETH_ADDR_LEN],
110
tag_type mac_learning_changed(struct mac_learning *, struct mac_entry *);
128
OVS_REQ_WRLOCK(ml->rwlock);
129
void mac_learning_changed(struct mac_learning *ml, struct mac_entry *e)
130
OVS_REQ_WRLOCK(ml->rwlock);
113
struct mac_entry *mac_learning_lookup(const struct mac_learning *,
133
struct mac_entry *mac_learning_lookup(const struct mac_learning *ml,
114
134
const uint8_t dst[ETH_ADDR_LEN],
115
uint16_t vlan, tag_type *);
135
uint16_t vlan, tag_type *)
136
OVS_REQ_RDLOCK(ml->rwlock);
118
void mac_learning_expire(struct mac_learning *, struct mac_entry *);
119
void mac_learning_flush(struct mac_learning *, struct tag_set *);
139
void mac_learning_expire(struct mac_learning *ml, struct mac_entry *e)
140
OVS_REQ_WRLOCK(ml->rwlock);
141
void mac_learning_flush(struct mac_learning *ml, struct tag_set *)
142
OVS_REQ_WRLOCK(ml->rwlock);
121
144
#endif /* mac-learning.h */