2 * Copyright (c) 2008, 2009 Nicira Networks.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef MAC_LEARNING_H
18 #define MAC_LEARNING_H 1
25 #define MAC_HASH_BITS 10
26 #define MAC_HASH_MASK (MAC_HASH_SIZE - 1)
27 #define MAC_HASH_SIZE (1u << MAC_HASH_BITS)
31 /* A MAC learning table entry. */
33 struct list hash_node; /* Element in a mac_learning 'table' list. */
34 struct list lru_node; /* Element in 'lrus' or 'free' list. */
35 time_t expires; /* Expiration time. */
36 uint8_t mac[ETH_ADDR_LEN]; /* Known MAC address. */
37 uint16_t vlan; /* VLAN tag. */
38 int port; /* Port on which MAC was most recently seen. */
39 tag_type tag; /* Tag for this learning entry. */
42 /* MAC learning table. */
44 struct list free; /* Not-in-use entries. */
45 struct list lrus; /* In-use entries, least recently used at the
46 front, most recently used at the back. */
47 struct list table[MAC_HASH_SIZE]; /* Hash table. */
48 struct mac_entry entries[MAC_MAX]; /* All entries. */
49 uint32_t secret; /* Secret for */
52 struct mac_learning *mac_learning_create(void);
53 void mac_learning_destroy(struct mac_learning *);
54 tag_type mac_learning_learn(struct mac_learning *,
55 const uint8_t src[ETH_ADDR_LEN], uint16_t vlan,
57 int mac_learning_lookup(const struct mac_learning *,
58 const uint8_t dst[ETH_ADDR_LEN], uint16_t vlan);
59 int mac_learning_lookup_tag(const struct mac_learning *,
60 const uint8_t dst[ETH_ADDR_LEN],
61 uint16_t vlan, tag_type *tag);
62 void mac_learning_flush(struct mac_learning *);
63 void mac_learning_run(struct mac_learning *, struct tag_set *);
64 void mac_learning_wait(struct mac_learning *);
66 #endif /* mac-learning.h */