Lines Matching refs:neigh
56 static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid);
92 static int neigh_blackhole(struct neighbour *neigh, struct sk_buff *skb) in neigh_blackhole() argument
98 static void neigh_cleanup_and_release(struct neighbour *neigh) in neigh_cleanup_and_release() argument
100 trace_neigh_cleanup_and_release(neigh, 0); in neigh_cleanup_and_release()
101 __neigh_notify(neigh, RTM_DELNEIGH, 0, 0); in neigh_cleanup_and_release()
102 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh); in neigh_cleanup_and_release()
103 neigh_release(neigh); in neigh_cleanup_and_release()
179 static void neigh_update_flags(struct neighbour *neigh, u32 flags, int *notify, in neigh_update_flags() argument
182 u32 ndm_flags, old_flags = neigh->flags; in neigh_update_flags()
192 neigh->flags |= NTF_EXT_LEARNED; in neigh_update_flags()
194 neigh->flags &= ~NTF_EXT_LEARNED; in neigh_update_flags()
200 neigh->flags |= NTF_MANAGED; in neigh_update_flags()
202 neigh->flags &= ~NTF_MANAGED; in neigh_update_flags()
215 struct neighbour *neigh; in neigh_del() local
217 neigh = rcu_dereference_protected(n->next, in neigh_del()
219 rcu_assign_pointer(*np, neigh); in neigh_del()
859 void neigh_destroy(struct neighbour *neigh) in neigh_destroy() argument
861 struct net_device *dev = neigh->dev; in neigh_destroy()
863 NEIGH_CACHE_STAT_INC(neigh->tbl, destroys); in neigh_destroy()
865 if (!neigh->dead) { in neigh_destroy()
866 pr_warn("Destroying alive neighbour %p\n", neigh); in neigh_destroy()
871 if (neigh_del_timer(neigh)) in neigh_destroy()
874 write_lock_bh(&neigh->lock); in neigh_destroy()
875 __skb_queue_purge(&neigh->arp_queue); in neigh_destroy()
876 write_unlock_bh(&neigh->lock); in neigh_destroy()
877 neigh->arp_queue_len_bytes = 0; in neigh_destroy()
880 dev->netdev_ops->ndo_neigh_destroy(dev, neigh); in neigh_destroy()
883 neigh_parms_put(neigh->parms); in neigh_destroy()
885 neigh_dbg(2, "neigh %p is destroyed\n", neigh); in neigh_destroy()
887 atomic_dec(&neigh->tbl->entries); in neigh_destroy()
888 kfree_rcu(neigh, rcu); in neigh_destroy()
897 static void neigh_suspect(struct neighbour *neigh) in neigh_suspect() argument
899 neigh_dbg(2, "neigh %p is suspected\n", neigh); in neigh_suspect()
901 neigh->output = neigh->ops->output; in neigh_suspect()
909 static void neigh_connect(struct neighbour *neigh) in neigh_connect() argument
911 neigh_dbg(2, "neigh %p is connected\n", neigh); in neigh_connect()
913 neigh->output = neigh->ops->connected_output; in neigh_connect()
1006 static void neigh_invalidate(struct neighbour *neigh) in neigh_invalidate() argument
1007 __releases(neigh->lock) in neigh_invalidate()
1008 __acquires(neigh->lock) in neigh_invalidate()
1012 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed); in neigh_invalidate()
1013 neigh_dbg(2, "neigh %p is failed\n", neigh); in neigh_invalidate()
1014 neigh->updated = jiffies; in neigh_invalidate()
1021 while (neigh->nud_state == NUD_FAILED && in neigh_invalidate()
1022 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) { in neigh_invalidate()
1023 write_unlock(&neigh->lock); in neigh_invalidate()
1024 neigh->ops->error_report(neigh, skb); in neigh_invalidate()
1025 write_lock(&neigh->lock); in neigh_invalidate()
1027 __skb_queue_purge(&neigh->arp_queue); in neigh_invalidate()
1028 neigh->arp_queue_len_bytes = 0; in neigh_invalidate()
1031 static void neigh_probe(struct neighbour *neigh) in neigh_probe() argument
1032 __releases(neigh->lock) in neigh_probe()
1034 struct sk_buff *skb = skb_peek_tail(&neigh->arp_queue); in neigh_probe()
1038 write_unlock(&neigh->lock); in neigh_probe()
1039 if (neigh->ops->solicit) in neigh_probe()
1040 neigh->ops->solicit(neigh, skb); in neigh_probe()
1041 atomic_inc(&neigh->probes); in neigh_probe()
1050 struct neighbour *neigh = from_timer(neigh, t, timer); in neigh_timer_handler() local
1054 write_lock(&neigh->lock); in neigh_timer_handler()
1056 state = neigh->nud_state; in neigh_timer_handler()
1065 neigh->confirmed + neigh->parms->reachable_time)) { in neigh_timer_handler()
1066 neigh_dbg(2, "neigh %p is still alive\n", neigh); in neigh_timer_handler()
1067 next = neigh->confirmed + neigh->parms->reachable_time; in neigh_timer_handler()
1069 neigh->used + in neigh_timer_handler()
1070 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) { in neigh_timer_handler()
1071 neigh_dbg(2, "neigh %p is delayed\n", neigh); in neigh_timer_handler()
1072 neigh->nud_state = NUD_DELAY; in neigh_timer_handler()
1073 neigh->updated = jiffies; in neigh_timer_handler()
1074 neigh_suspect(neigh); in neigh_timer_handler()
1075 next = now + NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME); in neigh_timer_handler()
1077 neigh_dbg(2, "neigh %p is suspected\n", neigh); in neigh_timer_handler()
1078 neigh->nud_state = NUD_STALE; in neigh_timer_handler()
1079 neigh->updated = jiffies; in neigh_timer_handler()
1080 neigh_suspect(neigh); in neigh_timer_handler()
1085 neigh->confirmed + in neigh_timer_handler()
1086 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) { in neigh_timer_handler()
1087 neigh_dbg(2, "neigh %p is now reachable\n", neigh); in neigh_timer_handler()
1088 neigh->nud_state = NUD_REACHABLE; in neigh_timer_handler()
1089 neigh->updated = jiffies; in neigh_timer_handler()
1090 neigh_connect(neigh); in neigh_timer_handler()
1092 next = neigh->confirmed + neigh->parms->reachable_time; in neigh_timer_handler()
1094 neigh_dbg(2, "neigh %p is probed\n", neigh); in neigh_timer_handler()
1095 neigh->nud_state = NUD_PROBE; in neigh_timer_handler()
1096 neigh->updated = jiffies; in neigh_timer_handler()
1097 atomic_set(&neigh->probes, 0); in neigh_timer_handler()
1099 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), in neigh_timer_handler()
1104 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), HZ/100); in neigh_timer_handler()
1107 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) && in neigh_timer_handler()
1108 atomic_read(&neigh->probes) >= neigh_max_probes(neigh)) { in neigh_timer_handler()
1109 neigh->nud_state = NUD_FAILED; in neigh_timer_handler()
1111 neigh_invalidate(neigh); in neigh_timer_handler()
1115 if (neigh->nud_state & NUD_IN_TIMER) { in neigh_timer_handler()
1118 if (!mod_timer(&neigh->timer, next)) in neigh_timer_handler()
1119 neigh_hold(neigh); in neigh_timer_handler()
1121 if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) { in neigh_timer_handler()
1122 neigh_probe(neigh); in neigh_timer_handler()
1125 write_unlock(&neigh->lock); in neigh_timer_handler()
1129 neigh_update_notify(neigh, 0); in neigh_timer_handler()
1131 trace_neigh_timer_handler(neigh, 0); in neigh_timer_handler()
1133 neigh_release(neigh); in neigh_timer_handler()
1136 int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb) in __neigh_event_send() argument
1141 write_lock_bh(&neigh->lock); in __neigh_event_send()
1144 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE)) in __neigh_event_send()
1146 if (neigh->dead) in __neigh_event_send()
1149 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) { in __neigh_event_send()
1150 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) + in __neigh_event_send()
1151 NEIGH_VAR(neigh->parms, APP_PROBES)) { in __neigh_event_send()
1154 atomic_set(&neigh->probes, in __neigh_event_send()
1155 NEIGH_VAR(neigh->parms, UCAST_PROBES)); in __neigh_event_send()
1156 neigh_del_timer(neigh); in __neigh_event_send()
1157 neigh->nud_state = NUD_INCOMPLETE; in __neigh_event_send()
1158 neigh->updated = now; in __neigh_event_send()
1159 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), in __neigh_event_send()
1161 neigh_add_timer(neigh, next); in __neigh_event_send()
1164 neigh->nud_state = NUD_FAILED; in __neigh_event_send()
1165 neigh->updated = jiffies; in __neigh_event_send()
1166 write_unlock_bh(&neigh->lock); in __neigh_event_send()
1171 } else if (neigh->nud_state & NUD_STALE) { in __neigh_event_send()
1172 neigh_dbg(2, "neigh %p is delayed\n", neigh); in __neigh_event_send()
1173 neigh_del_timer(neigh); in __neigh_event_send()
1174 neigh->nud_state = NUD_DELAY; in __neigh_event_send()
1175 neigh->updated = jiffies; in __neigh_event_send()
1176 neigh_add_timer(neigh, jiffies + in __neigh_event_send()
1177 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME)); in __neigh_event_send()
1180 if (neigh->nud_state == NUD_INCOMPLETE) { in __neigh_event_send()
1182 while (neigh->arp_queue_len_bytes + skb->truesize > in __neigh_event_send()
1183 NEIGH_VAR(neigh->parms, QUEUE_LEN_BYTES)) { in __neigh_event_send()
1186 buff = __skb_dequeue(&neigh->arp_queue); in __neigh_event_send()
1189 neigh->arp_queue_len_bytes -= buff->truesize; in __neigh_event_send()
1191 NEIGH_CACHE_STAT_INC(neigh->tbl, unres_discards); in __neigh_event_send()
1194 __skb_queue_tail(&neigh->arp_queue, skb); in __neigh_event_send()
1195 neigh->arp_queue_len_bytes += skb->truesize; in __neigh_event_send()
1201 neigh_probe(neigh); in __neigh_event_send()
1203 write_unlock(&neigh->lock); in __neigh_event_send()
1205 trace_neigh_event_send_done(neigh, rc); in __neigh_event_send()
1209 if (neigh->nud_state & NUD_STALE) in __neigh_event_send()
1211 write_unlock_bh(&neigh->lock); in __neigh_event_send()
1213 trace_neigh_event_send_dead(neigh, 1); in __neigh_event_send()
1218 static void neigh_update_hhs(struct neighbour *neigh) in neigh_update_hhs() argument
1224 if (neigh->dev->header_ops) in neigh_update_hhs()
1225 update = neigh->dev->header_ops->cache_update; in neigh_update_hhs()
1228 hh = &neigh->hh; in neigh_update_hhs()
1231 update(hh, neigh->dev, neigh->ha); in neigh_update_hhs()
1256 static int __neigh_update(struct neighbour *neigh, const u8 *lladdr, in __neigh_update() argument
1266 trace_neigh_update(neigh, lladdr, new, flags, nlmsg_pid); in __neigh_update()
1268 write_lock_bh(&neigh->lock); in __neigh_update()
1270 dev = neigh->dev; in __neigh_update()
1271 old = neigh->nud_state; in __neigh_update()
1274 if (neigh->dead) { in __neigh_update()
1283 neigh_update_flags(neigh, flags, ¬ify, &gc_update, &managed_update); in __neigh_update()
1286 neigh->nud_state = new; in __neigh_update()
1292 neigh_del_timer(neigh); in __neigh_update()
1294 neigh_suspect(neigh); in __neigh_update()
1295 neigh->nud_state = new; in __neigh_update()
1300 neigh_invalidate(neigh); in __neigh_update()
1309 lladdr = neigh->ha; in __neigh_update()
1317 !memcmp(lladdr, neigh->ha, dev->addr_len)) in __neigh_update()
1318 lladdr = neigh->ha; in __neigh_update()
1328 lladdr = neigh->ha; in __neigh_update()
1335 neigh->confirmed = jiffies; in __neigh_update()
1343 if (lladdr != neigh->ha && !(flags & NEIGH_UPDATE_F_OVERRIDE)) { in __neigh_update()
1347 lladdr = neigh->ha; in __neigh_update()
1352 if (lladdr == neigh->ha && new == NUD_STALE && in __neigh_update()
1362 if (new != old || lladdr != neigh->ha) in __neigh_update()
1363 neigh->updated = jiffies; in __neigh_update()
1366 neigh_del_timer(neigh); in __neigh_update()
1368 atomic_set(&neigh->probes, 0); in __neigh_update()
1370 neigh_add_timer(neigh, (jiffies + in __neigh_update()
1372 neigh->parms->reachable_time : in __neigh_update()
1374 neigh->nud_state = new; in __neigh_update()
1378 if (lladdr != neigh->ha) { in __neigh_update()
1379 write_seqlock(&neigh->ha_lock); in __neigh_update()
1380 memcpy(&neigh->ha, lladdr, dev->addr_len); in __neigh_update()
1381 write_sequnlock(&neigh->ha_lock); in __neigh_update()
1382 neigh_update_hhs(neigh); in __neigh_update()
1384 neigh->confirmed = jiffies - in __neigh_update()
1385 (NEIGH_VAR(neigh->parms, BASE_REACHABLE_TIME) << 1); in __neigh_update()
1391 neigh_connect(neigh); in __neigh_update()
1393 neigh_suspect(neigh); in __neigh_update()
1399 while (neigh->nud_state & NUD_VALID && in __neigh_update()
1400 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) { in __neigh_update()
1402 struct neighbour *n2, *n1 = neigh; in __neigh_update()
1403 write_unlock_bh(&neigh->lock); in __neigh_update()
1425 write_lock_bh(&neigh->lock); in __neigh_update()
1427 __skb_queue_purge(&neigh->arp_queue); in __neigh_update()
1428 neigh->arp_queue_len_bytes = 0; in __neigh_update()
1432 neigh_update_is_router(neigh, flags, ¬ify); in __neigh_update()
1433 write_unlock_bh(&neigh->lock); in __neigh_update()
1435 neigh_update_gc_list(neigh); in __neigh_update()
1437 neigh_update_managed_list(neigh); in __neigh_update()
1439 neigh_update_notify(neigh, nlmsg_pid); in __neigh_update()
1440 trace_neigh_update_done(neigh, err); in __neigh_update()
1444 int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, in neigh_update() argument
1447 return __neigh_update(neigh, lladdr, new, flags, nlmsg_pid, NULL); in neigh_update()
1454 void __neigh_set_probe_once(struct neighbour *neigh) in __neigh_set_probe_once() argument
1456 if (neigh->dead) in __neigh_set_probe_once()
1458 neigh->updated = jiffies; in __neigh_set_probe_once()
1459 if (!(neigh->nud_state & NUD_FAILED)) in __neigh_set_probe_once()
1461 neigh->nud_state = NUD_INCOMPLETE; in __neigh_set_probe_once()
1462 atomic_set(&neigh->probes, neigh_max_probes(neigh)); in __neigh_set_probe_once()
1463 neigh_add_timer(neigh, in __neigh_set_probe_once()
1464 jiffies + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), in __neigh_set_probe_once()
1473 struct neighbour *neigh = __neigh_lookup(tbl, saddr, dev, in neigh_event_ns() local
1475 if (neigh) in neigh_event_ns()
1476 neigh_update(neigh, lladdr, NUD_STALE, in neigh_event_ns()
1478 return neigh; in neigh_event_ns()
1502 int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb) in neigh_resolve_output() argument
1506 if (!neigh_event_send(neigh, skb)) { in neigh_resolve_output()
1508 struct net_device *dev = neigh->dev; in neigh_resolve_output()
1511 if (dev->header_ops->cache && !READ_ONCE(neigh->hh.hh_len)) in neigh_resolve_output()
1512 neigh_hh_init(neigh); in neigh_resolve_output()
1516 seq = read_seqbegin(&neigh->ha_lock); in neigh_resolve_output()
1518 neigh->ha, NULL, skb->len); in neigh_resolve_output()
1519 } while (read_seqretry(&neigh->ha_lock, seq)); in neigh_resolve_output()
1537 int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb) in neigh_connected_output() argument
1539 struct net_device *dev = neigh->dev; in neigh_connected_output()
1545 seq = read_seqbegin(&neigh->ha_lock); in neigh_connected_output()
1547 neigh->ha, NULL, skb->len); in neigh_connected_output()
1548 } while (read_seqretry(&neigh->ha_lock, seq)); in neigh_connected_output()
1560 int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb) in neigh_direct_output() argument
1570 struct neighbour *neigh; in neigh_managed_work() local
1573 list_for_each_entry(neigh, &tbl->managed_list, managed_list) in neigh_managed_work()
1574 neigh_event_send(neigh, NULL); in neigh_managed_work()
1848 struct neighbour *neigh; in neigh_delete() local
1888 neigh = neigh_lookup(tbl, nla_data(dst_attr), dev); in neigh_delete()
1889 if (neigh == NULL) { in neigh_delete()
1894 err = __neigh_update(neigh, NULL, NUD_FAILED, in neigh_delete()
1898 neigh_release(neigh); in neigh_delete()
1899 neigh_remove_one(neigh, tbl); in neigh_delete()
1916 struct neighbour *neigh; in neigh_add() local
1939 BUILD_BUG_ON(sizeof(neigh->flags) * BITS_PER_BYTE < in neigh_add()
2000 neigh = neigh_lookup(tbl, dst, dev); in neigh_add()
2001 if (neigh == NULL) { in neigh_add()
2016 neigh = ___neigh_create(tbl, dst, dev, in neigh_add()
2020 if (IS_ERR(neigh)) { in neigh_add()
2021 err = PTR_ERR(neigh); in neigh_add()
2027 neigh_release(neigh); in neigh_add()
2037 neigh->protocol = protocol; in neigh_add()
2047 err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags, in neigh_add()
2050 neigh_event_send(neigh, NULL); in neigh_add()
2053 neigh_release(neigh); in neigh_add()
2501 static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh, in neigh_fill_info() argument
2514 neigh_flags_ext = neigh->flags >> NTF_EXT_SHIFT; in neigh_fill_info()
2515 neigh_flags = neigh->flags & NTF_OLD_MASK; in neigh_fill_info()
2518 ndm->ndm_family = neigh->ops->family; in neigh_fill_info()
2522 ndm->ndm_type = neigh->type; in neigh_fill_info()
2523 ndm->ndm_ifindex = neigh->dev->ifindex; in neigh_fill_info()
2525 if (nla_put(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key)) in neigh_fill_info()
2528 read_lock_bh(&neigh->lock); in neigh_fill_info()
2529 ndm->ndm_state = neigh->nud_state; in neigh_fill_info()
2530 if (neigh->nud_state & NUD_VALID) { in neigh_fill_info()
2533 neigh_ha_snapshot(haddr, neigh, neigh->dev); in neigh_fill_info()
2534 if (nla_put(skb, NDA_LLADDR, neigh->dev->addr_len, haddr) < 0) { in neigh_fill_info()
2535 read_unlock_bh(&neigh->lock); in neigh_fill_info()
2540 ci.ndm_used = jiffies_to_clock_t(now - neigh->used); in neigh_fill_info()
2541 ci.ndm_confirmed = jiffies_to_clock_t(now - neigh->confirmed); in neigh_fill_info()
2542 ci.ndm_updated = jiffies_to_clock_t(now - neigh->updated); in neigh_fill_info()
2543 ci.ndm_refcnt = refcount_read(&neigh->refcnt) - 1; in neigh_fill_info()
2544 read_unlock_bh(&neigh->lock); in neigh_fill_info()
2546 if (nla_put_u32(skb, NDA_PROBES, atomic_read(&neigh->probes)) || in neigh_fill_info()
2550 if (neigh->protocol && nla_put_u8(skb, NDA_PROTOCOL, neigh->protocol)) in neigh_fill_info()
2603 static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid) in neigh_update_notify() argument
2605 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh); in neigh_update_notify()
2606 __neigh_notify(neigh, RTM_NEWNEIGH, 0, nlmsg_pid); in neigh_update_notify()
2913 static int neigh_get_reply(struct net *net, struct neighbour *neigh, in neigh_get_reply() argument
2923 err = neigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0); in neigh_get_reply()
2942 static int pneigh_get_reply(struct net *net, struct pneigh_entry *neigh, in pneigh_get_reply() argument
2952 err = pneigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0, tbl); in pneigh_get_reply()
2969 struct neighbour *neigh; in neigh_get() local
3010 neigh = neigh_lookup(tbl, dst, dev); in neigh_get()
3011 if (!neigh) { in neigh_get()
3016 err = neigh_get_reply(net, neigh, NETLINK_CB(in_skb).portid, in neigh_get()
3019 neigh_release(neigh); in neigh_get()
3087 struct neighbour *neigh; in neigh_xmit() local
3096 neigh = __ipv4_neigh_lookup_noref(dev, key); in neigh_xmit()
3098 neigh = __neigh_lookup_noref(tbl, addr, dev); in neigh_xmit()
3100 if (!neigh) in neigh_xmit()
3101 neigh = __neigh_create(tbl, addr, dev, false); in neigh_xmit()
3102 err = PTR_ERR(neigh); in neigh_xmit()
3103 if (IS_ERR(neigh)) { in neigh_xmit()
3107 err = neigh->output(neigh, skb); in neigh_xmit()