Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Forwarding database |
| 3 | * Linux ethernet bridge |
| 4 | * |
| 5 | * Authors: |
| 6 | * Lennert Buytenhek <buytenh@gnu.org> |
| 7 | * |
| 8 | * $Id: br_fdb.c,v 1.6 2002/01/17 00:57:07 davem Exp $ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/spinlock.h> |
| 19 | #include <linux/times.h> |
| 20 | #include <linux/netdevice.h> |
| 21 | #include <linux/etherdevice.h> |
| 22 | #include <linux/jhash.h> |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 23 | #include <linux/random.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/atomic.h> |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "br_private.h" |
| 27 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 28 | static struct kmem_cache *br_fdb_cache __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source, |
| 30 | const unsigned char *addr); |
| 31 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 32 | static u32 fdb_salt __read_mostly; |
| 33 | |
Akinobu Mita | 87a596e | 2007-04-07 18:57:07 +0900 | [diff] [blame] | 34 | int __init br_fdb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
| 36 | br_fdb_cache = kmem_cache_create("bridge_fdb_cache", |
| 37 | sizeof(struct net_bridge_fdb_entry), |
| 38 | 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 39 | SLAB_HWCACHE_ALIGN, NULL); |
Akinobu Mita | 87a596e | 2007-04-07 18:57:07 +0900 | [diff] [blame] | 40 | if (!br_fdb_cache) |
| 41 | return -ENOMEM; |
| 42 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 43 | get_random_bytes(&fdb_salt, sizeof(fdb_salt)); |
Akinobu Mita | 87a596e | 2007-04-07 18:57:07 +0900 | [diff] [blame] | 44 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void __exit br_fdb_fini(void) |
| 48 | { |
| 49 | kmem_cache_destroy(br_fdb_cache); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /* if topology_changing then use forward_delay (default 15 sec) |
| 54 | * otherwise keep longer (default 5 minutes) |
| 55 | */ |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 56 | static inline unsigned long hold_time(const struct net_bridge *br) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
| 58 | return br->topology_change ? br->forward_delay : br->ageing_time; |
| 59 | } |
| 60 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 61 | static inline int has_expired(const struct net_bridge *br, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | const struct net_bridge_fdb_entry *fdb) |
| 63 | { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 64 | return !fdb->is_static |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | && time_before_eq(fdb->ageing_timer + hold_time(br), jiffies); |
| 66 | } |
| 67 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 68 | static inline int br_mac_hash(const unsigned char *mac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 70 | /* use 1 byte of OUI cnd 3 bytes of NIC */ |
| 71 | u32 key = get_unaligned((u32 *)(mac + 2)); |
| 72 | return jhash_1word(key, fdb_salt) & (BR_HASH_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Stephen Hemminger | 3f89092 | 2007-03-21 13:42:33 -0700 | [diff] [blame] | 75 | static inline void fdb_delete(struct net_bridge_fdb_entry *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
| 77 | hlist_del_rcu(&f->hlist); |
| 78 | br_fdb_put(f); |
| 79 | } |
| 80 | |
| 81 | void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr) |
| 82 | { |
| 83 | struct net_bridge *br = p->br; |
| 84 | int i; |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | spin_lock_bh(&br->hash_lock); |
| 87 | |
| 88 | /* Search all chains since old address/hash is unknown */ |
| 89 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 90 | struct hlist_node *h; |
| 91 | hlist_for_each(h, &br->hash[i]) { |
| 92 | struct net_bridge_fdb_entry *f; |
| 93 | |
| 94 | f = hlist_entry(h, struct net_bridge_fdb_entry, hlist); |
| 95 | if (f->dst == p && f->is_local) { |
| 96 | /* maybe another port has same hw addr? */ |
| 97 | struct net_bridge_port *op; |
| 98 | list_for_each_entry(op, &br->port_list, list) { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 99 | if (op != p && |
Stephen Hemminger | 6ede246 | 2005-10-25 15:04:59 -0700 | [diff] [blame] | 100 | !compare_ether_addr(op->dev->dev_addr, |
| 101 | f->addr.addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | f->dst = op; |
| 103 | goto insert; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* delete old one */ |
| 108 | fdb_delete(f); |
| 109 | goto insert; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | insert: |
| 114 | /* insert new address, may fail if invalid address or dup. */ |
| 115 | fdb_insert(br, p, newaddr); |
| 116 | |
| 117 | spin_unlock_bh(&br->hash_lock); |
| 118 | } |
| 119 | |
| 120 | void br_fdb_cleanup(unsigned long _data) |
| 121 | { |
| 122 | struct net_bridge *br = (struct net_bridge *)_data; |
| 123 | unsigned long delay = hold_time(br); |
Baruch Even | 071f772 | 2007-05-31 01:20:45 -0700 | [diff] [blame] | 124 | unsigned long next_timer = jiffies + br->forward_delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | int i; |
| 126 | |
| 127 | spin_lock_bh(&br->hash_lock); |
| 128 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 129 | struct net_bridge_fdb_entry *f; |
| 130 | struct hlist_node *h, *n; |
| 131 | |
| 132 | hlist_for_each_entry_safe(f, h, n, &br->hash[i], hlist) { |
Baruch Even | 071f772 | 2007-05-31 01:20:45 -0700 | [diff] [blame] | 133 | unsigned long this_timer; |
| 134 | if (f->is_static) |
| 135 | continue; |
| 136 | this_timer = f->ageing_timer + delay; |
| 137 | if (time_before_eq(this_timer, jiffies)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | fdb_delete(f); |
Baruch Even | 071f772 | 2007-05-31 01:20:45 -0700 | [diff] [blame] | 139 | else if (this_timer < next_timer) |
| 140 | next_timer = this_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | spin_unlock_bh(&br->hash_lock); |
| 144 | |
Baruch Even | 071f772 | 2007-05-31 01:20:45 -0700 | [diff] [blame] | 145 | /* Add HZ/4 to ensure we round the jiffies upwards to be after the next |
| 146 | * timer, otherwise we might round down and will have no-op run. */ |
| 147 | mod_timer(&br->gc_timer, round_jiffies(next_timer + HZ/4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 150 | /* Completely flush all dynamic entries in forwarding database.*/ |
| 151 | void br_fdb_flush(struct net_bridge *br) |
| 152 | { |
| 153 | int i; |
Stephen Hemminger | 1a62069 | 2006-10-12 14:45:38 -0700 | [diff] [blame] | 154 | |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 155 | spin_lock_bh(&br->hash_lock); |
| 156 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 157 | struct net_bridge_fdb_entry *f; |
| 158 | struct hlist_node *h, *n; |
| 159 | hlist_for_each_entry_safe(f, h, n, &br->hash[i], hlist) { |
| 160 | if (!f->is_static) |
| 161 | fdb_delete(f); |
| 162 | } |
| 163 | } |
| 164 | spin_unlock_bh(&br->hash_lock); |
| 165 | } |
| 166 | |
| 167 | /* Flush all entries refering to a specific port. |
| 168 | * if do_all is set also flush static entries |
| 169 | */ |
Stephen Hemminger | 1a62069 | 2006-10-12 14:45:38 -0700 | [diff] [blame] | 170 | void br_fdb_delete_by_port(struct net_bridge *br, |
| 171 | const struct net_bridge_port *p, |
| 172 | int do_all) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
| 174 | int i; |
| 175 | |
| 176 | spin_lock_bh(&br->hash_lock); |
| 177 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 178 | struct hlist_node *h, *g; |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | hlist_for_each_safe(h, g, &br->hash[i]) { |
| 181 | struct net_bridge_fdb_entry *f |
| 182 | = hlist_entry(h, struct net_bridge_fdb_entry, hlist); |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 183 | if (f->dst != p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | continue; |
| 185 | |
Stephen Hemminger | 1a62069 | 2006-10-12 14:45:38 -0700 | [diff] [blame] | 186 | if (f->is_static && !do_all) |
| 187 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /* |
| 189 | * if multiple ports all have the same device address |
| 190 | * then when one port is deleted, assign |
| 191 | * the local entry to other port |
| 192 | */ |
| 193 | if (f->is_local) { |
| 194 | struct net_bridge_port *op; |
| 195 | list_for_each_entry(op, &br->port_list, list) { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 196 | if (op != p && |
Stephen Hemminger | 6ede246 | 2005-10-25 15:04:59 -0700 | [diff] [blame] | 197 | !compare_ether_addr(op->dev->dev_addr, |
| 198 | f->addr.addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | f->dst = op; |
| 200 | goto skip_delete; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | fdb_delete(f); |
| 206 | skip_delete: ; |
| 207 | } |
| 208 | } |
| 209 | spin_unlock_bh(&br->hash_lock); |
| 210 | } |
| 211 | |
| 212 | /* No locking or refcounting, assumes caller has no preempt (rcu_read_lock) */ |
| 213 | struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br, |
| 214 | const unsigned char *addr) |
| 215 | { |
| 216 | struct hlist_node *h; |
| 217 | struct net_bridge_fdb_entry *fdb; |
| 218 | |
| 219 | hlist_for_each_entry_rcu(fdb, h, &br->hash[br_mac_hash(addr)], hlist) { |
Stephen Hemminger | 6ede246 | 2005-10-25 15:04:59 -0700 | [diff] [blame] | 220 | if (!compare_ether_addr(fdb->addr.addr, addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | if (unlikely(has_expired(br, fdb))) |
| 222 | break; |
| 223 | return fdb; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | /* Interface used by ATM hook that keeps a ref count */ |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 231 | struct net_bridge_fdb_entry *br_fdb_get(struct net_bridge *br, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | unsigned char *addr) |
| 233 | { |
| 234 | struct net_bridge_fdb_entry *fdb; |
| 235 | |
| 236 | rcu_read_lock(); |
| 237 | fdb = __br_fdb_get(br, addr); |
Patrick McHardy | b19cbe2 | 2007-03-22 12:25:20 -0700 | [diff] [blame] | 238 | if (fdb && !atomic_inc_not_zero(&fdb->use_count)) |
| 239 | fdb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | rcu_read_unlock(); |
| 241 | return fdb; |
| 242 | } |
| 243 | |
| 244 | static void fdb_rcu_free(struct rcu_head *head) |
| 245 | { |
| 246 | struct net_bridge_fdb_entry *ent |
| 247 | = container_of(head, struct net_bridge_fdb_entry, rcu); |
| 248 | kmem_cache_free(br_fdb_cache, ent); |
| 249 | } |
| 250 | |
| 251 | /* Set entry up for deletion with RCU */ |
| 252 | void br_fdb_put(struct net_bridge_fdb_entry *ent) |
| 253 | { |
| 254 | if (atomic_dec_and_test(&ent->use_count)) |
| 255 | call_rcu(&ent->rcu, fdb_rcu_free); |
| 256 | } |
| 257 | |
| 258 | /* |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 259 | * Fill buffer with forwarding table records in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | * the API format. |
| 261 | */ |
| 262 | int br_fdb_fillbuf(struct net_bridge *br, void *buf, |
| 263 | unsigned long maxnum, unsigned long skip) |
| 264 | { |
| 265 | struct __fdb_entry *fe = buf; |
| 266 | int i, num = 0; |
| 267 | struct hlist_node *h; |
| 268 | struct net_bridge_fdb_entry *f; |
| 269 | |
| 270 | memset(buf, 0, maxnum*sizeof(struct __fdb_entry)); |
| 271 | |
| 272 | rcu_read_lock(); |
| 273 | for (i = 0; i < BR_HASH_SIZE; i++) { |
| 274 | hlist_for_each_entry_rcu(f, h, &br->hash[i], hlist) { |
| 275 | if (num >= maxnum) |
| 276 | goto out; |
| 277 | |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 278 | if (has_expired(br, f)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | continue; |
| 280 | |
| 281 | if (skip) { |
| 282 | --skip; |
| 283 | continue; |
| 284 | } |
| 285 | |
| 286 | /* convert from internal format to API */ |
| 287 | memcpy(fe->mac_addr, f->addr.addr, ETH_ALEN); |
| 288 | fe->port_no = f->dst->port_no; |
| 289 | fe->is_local = f->is_local; |
| 290 | if (!f->is_static) |
| 291 | fe->ageing_timer_value = jiffies_to_clock_t(jiffies - f->ageing_timer); |
| 292 | ++fe; |
| 293 | ++num; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | out: |
| 298 | rcu_read_unlock(); |
| 299 | |
| 300 | return num; |
| 301 | } |
| 302 | |
| 303 | static inline struct net_bridge_fdb_entry *fdb_find(struct hlist_head *head, |
| 304 | const unsigned char *addr) |
| 305 | { |
| 306 | struct hlist_node *h; |
| 307 | struct net_bridge_fdb_entry *fdb; |
| 308 | |
| 309 | hlist_for_each_entry_rcu(fdb, h, head, hlist) { |
Stephen Hemminger | 6ede246 | 2005-10-25 15:04:59 -0700 | [diff] [blame] | 310 | if (!compare_ether_addr(fdb->addr.addr, addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | return fdb; |
| 312 | } |
| 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head, |
| 317 | struct net_bridge_port *source, |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 318 | const unsigned char *addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | int is_local) |
| 320 | { |
| 321 | struct net_bridge_fdb_entry *fdb; |
| 322 | |
| 323 | fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC); |
| 324 | if (fdb) { |
| 325 | memcpy(fdb->addr.addr, addr, ETH_ALEN); |
| 326 | atomic_set(&fdb->use_count, 1); |
| 327 | hlist_add_head_rcu(&fdb->hlist, head); |
| 328 | |
| 329 | fdb->dst = source; |
| 330 | fdb->is_local = is_local; |
| 331 | fdb->is_static = is_local; |
| 332 | fdb->ageing_timer = jiffies; |
| 333 | } |
| 334 | return fdb; |
| 335 | } |
| 336 | |
| 337 | static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source, |
| 338 | const unsigned char *addr) |
| 339 | { |
| 340 | struct hlist_head *head = &br->hash[br_mac_hash(addr)]; |
| 341 | struct net_bridge_fdb_entry *fdb; |
| 342 | |
| 343 | if (!is_valid_ether_addr(addr)) |
| 344 | return -EINVAL; |
| 345 | |
| 346 | fdb = fdb_find(head, addr); |
| 347 | if (fdb) { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 348 | /* it is okay to have multiple ports with same |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | * address, just use the first one. |
| 350 | */ |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 351 | if (fdb->is_local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return 0; |
| 353 | |
| 354 | printk(KERN_WARNING "%s adding interface with same address " |
| 355 | "as a received packet\n", |
| 356 | source->dev->name); |
| 357 | fdb_delete(fdb); |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | if (!fdb_create(head, source, addr, 1)) |
| 361 | return -ENOMEM; |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source, |
| 367 | const unsigned char *addr) |
| 368 | { |
| 369 | int ret; |
| 370 | |
| 371 | spin_lock_bh(&br->hash_lock); |
| 372 | ret = fdb_insert(br, source, addr); |
| 373 | spin_unlock_bh(&br->hash_lock); |
| 374 | return ret; |
| 375 | } |
| 376 | |
| 377 | void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, |
| 378 | const unsigned char *addr) |
| 379 | { |
| 380 | struct hlist_head *head = &br->hash[br_mac_hash(addr)]; |
| 381 | struct net_bridge_fdb_entry *fdb; |
| 382 | |
| 383 | /* some users want to always flood. */ |
| 384 | if (hold_time(br) == 0) |
| 385 | return; |
| 386 | |
Stephen Hemminger | df1c0b8 | 2007-08-30 22:15:35 -0700 | [diff] [blame] | 387 | /* ignore packets unless we are using this port */ |
| 388 | if (!(source->state == BR_STATE_LEARNING || |
| 389 | source->state == BR_STATE_FORWARDING)) |
| 390 | return; |
| 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | fdb = fdb_find(head, addr); |
| 393 | if (likely(fdb)) { |
| 394 | /* attempt to update an entry for a local interface */ |
| 395 | if (unlikely(fdb->is_local)) { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 396 | if (net_ratelimit()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | printk(KERN_WARNING "%s: received packet with " |
| 398 | " own address as source address\n", |
| 399 | source->dev->name); |
| 400 | } else { |
| 401 | /* fastpath: update of existing entry */ |
| 402 | fdb->dst = source; |
| 403 | fdb->ageing_timer = jiffies; |
| 404 | } |
| 405 | } else { |
Stephen Hemminger | f8ae737 | 2006-03-20 22:58:36 -0800 | [diff] [blame] | 406 | spin_lock(&br->hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | if (!fdb_find(head, addr)) |
| 408 | fdb_create(head, source, addr, 0); |
| 409 | /* else we lose race and someone else inserts |
| 410 | * it first, don't bother updating |
| 411 | */ |
Stephen Hemminger | f8ae737 | 2006-03-20 22:58:36 -0800 | [diff] [blame] | 412 | spin_unlock(&br->hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |