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()
902 void neigh_destroy(struct neighbour *neigh) in neigh_destroy() argument
904 struct net_device *dev = neigh->dev; in neigh_destroy()
906 NEIGH_CACHE_STAT_INC(neigh->tbl, destroys); in neigh_destroy()
908 if (!neigh->dead) { in neigh_destroy()
909 pr_warn("Destroying alive neighbour %p\n", neigh); in neigh_destroy()
914 if (neigh_del_timer(neigh)) in neigh_destroy()
917 write_lock_bh(&neigh->lock); in neigh_destroy()
918 __skb_queue_purge(&neigh->arp_queue); in neigh_destroy()
919 write_unlock_bh(&neigh->lock); in neigh_destroy()
920 neigh->arp_queue_len_bytes = 0; in neigh_destroy()
923 dev->netdev_ops->ndo_neigh_destroy(dev, neigh); in neigh_destroy()
925 netdev_put(dev, &neigh->dev_tracker); in neigh_destroy()
926 neigh_parms_put(neigh->parms); in neigh_destroy()
928 neigh_dbg(2, "neigh %p is destroyed\n", neigh); in neigh_destroy()
930 atomic_dec(&neigh->tbl->entries); in neigh_destroy()
931 kfree_rcu(neigh, rcu); in neigh_destroy()
940 static void neigh_suspect(struct neighbour *neigh) in neigh_suspect() argument
942 neigh_dbg(2, "neigh %p is suspected\n", neigh); in neigh_suspect()
944 neigh->output = neigh->ops->output; in neigh_suspect()
952 static void neigh_connect(struct neighbour *neigh) in neigh_connect() argument
954 neigh_dbg(2, "neigh %p is connected\n", neigh); in neigh_connect()
956 neigh->output = neigh->ops->connected_output; in neigh_connect()
1049 static void neigh_invalidate(struct neighbour *neigh) in neigh_invalidate() argument
1050 __releases(neigh->lock) in neigh_invalidate()
1051 __acquires(neigh->lock) in neigh_invalidate()
1055 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed); in neigh_invalidate()
1056 neigh_dbg(2, "neigh %p is failed\n", neigh); in neigh_invalidate()
1057 neigh->updated = jiffies; in neigh_invalidate()
1064 while (neigh->nud_state == NUD_FAILED && in neigh_invalidate()
1065 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) { in neigh_invalidate()
1066 write_unlock(&neigh->lock); in neigh_invalidate()
1067 neigh->ops->error_report(neigh, skb); in neigh_invalidate()
1068 write_lock(&neigh->lock); in neigh_invalidate()
1070 __skb_queue_purge(&neigh->arp_queue); in neigh_invalidate()
1071 neigh->arp_queue_len_bytes = 0; in neigh_invalidate()
1074 static void neigh_probe(struct neighbour *neigh) in neigh_probe() argument
1075 __releases(neigh->lock) in neigh_probe()
1077 struct sk_buff *skb = skb_peek_tail(&neigh->arp_queue); in neigh_probe()
1081 write_unlock(&neigh->lock); in neigh_probe()
1082 if (neigh->ops->solicit) in neigh_probe()
1083 neigh->ops->solicit(neigh, skb); in neigh_probe()
1084 atomic_inc(&neigh->probes); in neigh_probe()
1093 struct neighbour *neigh = from_timer(neigh, t, timer); in neigh_timer_handler() local
1097 write_lock(&neigh->lock); in neigh_timer_handler()
1099 state = neigh->nud_state; in neigh_timer_handler()
1108 neigh->confirmed + neigh->parms->reachable_time)) { in neigh_timer_handler()
1109 neigh_dbg(2, "neigh %p is still alive\n", neigh); in neigh_timer_handler()
1110 next = neigh->confirmed + neigh->parms->reachable_time; in neigh_timer_handler()
1112 neigh->used + in neigh_timer_handler()
1113 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) { in neigh_timer_handler()
1114 neigh_dbg(2, "neigh %p is delayed\n", neigh); in neigh_timer_handler()
1115 neigh->nud_state = NUD_DELAY; in neigh_timer_handler()
1116 neigh->updated = jiffies; in neigh_timer_handler()
1117 neigh_suspect(neigh); in neigh_timer_handler()
1118 next = now + NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME); in neigh_timer_handler()
1120 neigh_dbg(2, "neigh %p is suspected\n", neigh); in neigh_timer_handler()
1121 neigh->nud_state = NUD_STALE; in neigh_timer_handler()
1122 neigh->updated = jiffies; in neigh_timer_handler()
1123 neigh_suspect(neigh); in neigh_timer_handler()
1128 neigh->confirmed + in neigh_timer_handler()
1129 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) { in neigh_timer_handler()
1130 neigh_dbg(2, "neigh %p is now reachable\n", neigh); in neigh_timer_handler()
1131 neigh->nud_state = NUD_REACHABLE; in neigh_timer_handler()
1132 neigh->updated = jiffies; in neigh_timer_handler()
1133 neigh_connect(neigh); in neigh_timer_handler()
1135 next = neigh->confirmed + neigh->parms->reachable_time; in neigh_timer_handler()
1137 neigh_dbg(2, "neigh %p is probed\n", neigh); in neigh_timer_handler()
1138 neigh->nud_state = NUD_PROBE; in neigh_timer_handler()
1139 neigh->updated = jiffies; in neigh_timer_handler()
1140 atomic_set(&neigh->probes, 0); in neigh_timer_handler()
1142 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), in neigh_timer_handler()
1147 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), HZ/100); in neigh_timer_handler()
1150 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) && in neigh_timer_handler()
1151 atomic_read(&neigh->probes) >= neigh_max_probes(neigh)) { in neigh_timer_handler()
1152 neigh->nud_state = NUD_FAILED; in neigh_timer_handler()
1154 neigh_invalidate(neigh); in neigh_timer_handler()
1158 if (neigh->nud_state & NUD_IN_TIMER) { in neigh_timer_handler()
1161 if (!mod_timer(&neigh->timer, next)) in neigh_timer_handler()
1162 neigh_hold(neigh); in neigh_timer_handler()
1164 if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) { in neigh_timer_handler()
1165 neigh_probe(neigh); in neigh_timer_handler()
1168 write_unlock(&neigh->lock); in neigh_timer_handler()
1172 neigh_update_notify(neigh, 0); in neigh_timer_handler()
1174 trace_neigh_timer_handler(neigh, 0); in neigh_timer_handler()
1176 neigh_release(neigh); in neigh_timer_handler()
1179 int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb, in __neigh_event_send() argument
1185 write_lock_bh(&neigh->lock); in __neigh_event_send()
1188 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE)) in __neigh_event_send()
1190 if (neigh->dead) in __neigh_event_send()
1193 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) { in __neigh_event_send()
1194 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) + in __neigh_event_send()
1195 NEIGH_VAR(neigh->parms, APP_PROBES)) { in __neigh_event_send()
1198 atomic_set(&neigh->probes, in __neigh_event_send()
1199 NEIGH_VAR(neigh->parms, UCAST_PROBES)); in __neigh_event_send()
1200 neigh_del_timer(neigh); in __neigh_event_send()
1201 neigh->nud_state = NUD_INCOMPLETE; in __neigh_event_send()
1202 neigh->updated = now; in __neigh_event_send()
1207 next = now + max(NEIGH_VAR(neigh->parms, in __neigh_event_send()
1211 neigh_add_timer(neigh, next); in __neigh_event_send()
1213 neigh->nud_state = NUD_FAILED; in __neigh_event_send()
1214 neigh->updated = jiffies; in __neigh_event_send()
1215 write_unlock_bh(&neigh->lock); in __neigh_event_send()
1220 } else if (neigh->nud_state & NUD_STALE) { in __neigh_event_send()
1221 neigh_dbg(2, "neigh %p is delayed\n", neigh); in __neigh_event_send()
1222 neigh_del_timer(neigh); in __neigh_event_send()
1223 neigh->nud_state = NUD_DELAY; in __neigh_event_send()
1224 neigh->updated = jiffies; in __neigh_event_send()
1225 neigh_add_timer(neigh, jiffies + in __neigh_event_send()
1226 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME)); in __neigh_event_send()
1229 if (neigh->nud_state == NUD_INCOMPLETE) { in __neigh_event_send()
1231 while (neigh->arp_queue_len_bytes + skb->truesize > in __neigh_event_send()
1232 NEIGH_VAR(neigh->parms, QUEUE_LEN_BYTES)) { in __neigh_event_send()
1235 buff = __skb_dequeue(&neigh->arp_queue); in __neigh_event_send()
1238 neigh->arp_queue_len_bytes -= buff->truesize; in __neigh_event_send()
1240 NEIGH_CACHE_STAT_INC(neigh->tbl, unres_discards); in __neigh_event_send()
1243 __skb_queue_tail(&neigh->arp_queue, skb); in __neigh_event_send()
1244 neigh->arp_queue_len_bytes += skb->truesize; in __neigh_event_send()
1250 neigh_probe(neigh); in __neigh_event_send()
1252 write_unlock(&neigh->lock); in __neigh_event_send()
1254 trace_neigh_event_send_done(neigh, rc); in __neigh_event_send()
1258 if (neigh->nud_state & NUD_STALE) in __neigh_event_send()
1260 write_unlock_bh(&neigh->lock); in __neigh_event_send()
1262 trace_neigh_event_send_dead(neigh, 1); in __neigh_event_send()
1267 static void neigh_update_hhs(struct neighbour *neigh) in neigh_update_hhs() argument
1273 if (neigh->dev->header_ops) in neigh_update_hhs()
1274 update = neigh->dev->header_ops->cache_update; in neigh_update_hhs()
1277 hh = &neigh->hh; in neigh_update_hhs()
1280 update(hh, neigh->dev, neigh->ha); in neigh_update_hhs()
1305 static int __neigh_update(struct neighbour *neigh, const u8 *lladdr, in __neigh_update() argument
1315 trace_neigh_update(neigh, lladdr, new, flags, nlmsg_pid); in __neigh_update()
1317 write_lock_bh(&neigh->lock); in __neigh_update()
1319 dev = neigh->dev; in __neigh_update()
1320 old = neigh->nud_state; in __neigh_update()
1323 if (neigh->dead) { in __neigh_update()
1332 neigh_update_flags(neigh, flags, ¬ify, &gc_update, &managed_update); in __neigh_update()
1335 neigh->nud_state = new; in __neigh_update()
1341 neigh_del_timer(neigh); in __neigh_update()
1343 neigh_suspect(neigh); in __neigh_update()
1344 neigh->nud_state = new; in __neigh_update()
1349 neigh_invalidate(neigh); in __neigh_update()
1358 lladdr = neigh->ha; in __neigh_update()
1366 !memcmp(lladdr, neigh->ha, dev->addr_len)) in __neigh_update()
1367 lladdr = neigh->ha; in __neigh_update()
1377 lladdr = neigh->ha; in __neigh_update()
1384 neigh->confirmed = jiffies; in __neigh_update()
1392 if (lladdr != neigh->ha && !(flags & NEIGH_UPDATE_F_OVERRIDE)) { in __neigh_update()
1396 lladdr = neigh->ha; in __neigh_update()
1401 if (lladdr == neigh->ha && new == NUD_STALE && in __neigh_update()
1411 if (new != old || lladdr != neigh->ha) in __neigh_update()
1412 neigh->updated = jiffies; in __neigh_update()
1415 neigh_del_timer(neigh); in __neigh_update()
1417 atomic_set(&neigh->probes, 0); in __neigh_update()
1419 neigh_add_timer(neigh, (jiffies + in __neigh_update()
1421 neigh->parms->reachable_time : in __neigh_update()
1423 neigh->nud_state = new; in __neigh_update()
1427 if (lladdr != neigh->ha) { in __neigh_update()
1428 write_seqlock(&neigh->ha_lock); in __neigh_update()
1429 memcpy(&neigh->ha, lladdr, dev->addr_len); in __neigh_update()
1430 write_sequnlock(&neigh->ha_lock); in __neigh_update()
1431 neigh_update_hhs(neigh); in __neigh_update()
1433 neigh->confirmed = jiffies - in __neigh_update()
1434 (NEIGH_VAR(neigh->parms, BASE_REACHABLE_TIME) << 1); in __neigh_update()
1440 neigh_connect(neigh); in __neigh_update()
1442 neigh_suspect(neigh); in __neigh_update()
1448 while (neigh->nud_state & NUD_VALID && in __neigh_update()
1449 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) { in __neigh_update()
1451 struct neighbour *n2, *n1 = neigh; in __neigh_update()
1452 write_unlock_bh(&neigh->lock); in __neigh_update()
1474 write_lock_bh(&neigh->lock); in __neigh_update()
1476 __skb_queue_purge(&neigh->arp_queue); in __neigh_update()
1477 neigh->arp_queue_len_bytes = 0; in __neigh_update()
1481 neigh_update_is_router(neigh, flags, ¬ify); in __neigh_update()
1482 write_unlock_bh(&neigh->lock); in __neigh_update()
1484 neigh_update_gc_list(neigh); in __neigh_update()
1486 neigh_update_managed_list(neigh); in __neigh_update()
1488 neigh_update_notify(neigh, nlmsg_pid); in __neigh_update()
1489 trace_neigh_update_done(neigh, err); in __neigh_update()
1493 int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, in neigh_update() argument
1496 return __neigh_update(neigh, lladdr, new, flags, nlmsg_pid, NULL); in neigh_update()
1503 void __neigh_set_probe_once(struct neighbour *neigh) in __neigh_set_probe_once() argument
1505 if (neigh->dead) in __neigh_set_probe_once()
1507 neigh->updated = jiffies; in __neigh_set_probe_once()
1508 if (!(neigh->nud_state & NUD_FAILED)) in __neigh_set_probe_once()
1510 neigh->nud_state = NUD_INCOMPLETE; in __neigh_set_probe_once()
1511 atomic_set(&neigh->probes, neigh_max_probes(neigh)); in __neigh_set_probe_once()
1512 neigh_add_timer(neigh, in __neigh_set_probe_once()
1513 jiffies + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), in __neigh_set_probe_once()
1522 struct neighbour *neigh = __neigh_lookup(tbl, saddr, dev, in neigh_event_ns() local
1524 if (neigh) in neigh_event_ns()
1525 neigh_update(neigh, lladdr, NUD_STALE, in neigh_event_ns()
1527 return neigh; in neigh_event_ns()
1551 int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb) in neigh_resolve_output() argument
1555 if (!neigh_event_send(neigh, skb)) { in neigh_resolve_output()
1557 struct net_device *dev = neigh->dev; in neigh_resolve_output()
1560 if (dev->header_ops->cache && !READ_ONCE(neigh->hh.hh_len)) in neigh_resolve_output()
1561 neigh_hh_init(neigh); in neigh_resolve_output()
1565 seq = read_seqbegin(&neigh->ha_lock); in neigh_resolve_output()
1567 neigh->ha, NULL, skb->len); in neigh_resolve_output()
1568 } while (read_seqretry(&neigh->ha_lock, seq)); in neigh_resolve_output()
1586 int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb) in neigh_connected_output() argument
1588 struct net_device *dev = neigh->dev; in neigh_connected_output()
1594 seq = read_seqbegin(&neigh->ha_lock); in neigh_connected_output()
1596 neigh->ha, NULL, skb->len); in neigh_connected_output()
1597 } while (read_seqretry(&neigh->ha_lock, seq)); in neigh_connected_output()
1609 int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb) in neigh_direct_output() argument
1619 struct neighbour *neigh; in neigh_managed_work() local
1622 list_for_each_entry(neigh, &tbl->managed_list, managed_list) in neigh_managed_work()
1623 neigh_event_send_probe(neigh, NULL, false); in neigh_managed_work()
1899 struct neighbour *neigh; in neigh_delete() local
1939 neigh = neigh_lookup(tbl, nla_data(dst_attr), dev); in neigh_delete()
1940 if (neigh == NULL) { in neigh_delete()
1945 err = __neigh_update(neigh, NULL, NUD_FAILED, in neigh_delete()
1949 neigh_release(neigh); in neigh_delete()
1950 neigh_remove_one(neigh, tbl); in neigh_delete()
1967 struct neighbour *neigh; in neigh_add() local
1990 BUILD_BUG_ON(sizeof(neigh->flags) * BITS_PER_BYTE < in neigh_add()
2051 neigh = neigh_lookup(tbl, dst, dev); in neigh_add()
2052 if (neigh == NULL) { in neigh_add()
2067 neigh = ___neigh_create(tbl, dst, dev, in neigh_add()
2071 if (IS_ERR(neigh)) { in neigh_add()
2072 err = PTR_ERR(neigh); in neigh_add()
2078 neigh_release(neigh); in neigh_add()
2088 neigh->protocol = protocol; in neigh_add()
2098 err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags, in neigh_add()
2101 neigh_event_send(neigh, NULL); in neigh_add()
2104 neigh_release(neigh); in neigh_add()
2559 static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh, in neigh_fill_info() argument
2572 neigh_flags_ext = neigh->flags >> NTF_EXT_SHIFT; in neigh_fill_info()
2573 neigh_flags = neigh->flags & NTF_OLD_MASK; in neigh_fill_info()
2576 ndm->ndm_family = neigh->ops->family; in neigh_fill_info()
2580 ndm->ndm_type = neigh->type; in neigh_fill_info()
2581 ndm->ndm_ifindex = neigh->dev->ifindex; in neigh_fill_info()
2583 if (nla_put(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key)) in neigh_fill_info()
2586 read_lock_bh(&neigh->lock); in neigh_fill_info()
2587 ndm->ndm_state = neigh->nud_state; in neigh_fill_info()
2588 if (neigh->nud_state & NUD_VALID) { in neigh_fill_info()
2591 neigh_ha_snapshot(haddr, neigh, neigh->dev); in neigh_fill_info()
2592 if (nla_put(skb, NDA_LLADDR, neigh->dev->addr_len, haddr) < 0) { in neigh_fill_info()
2593 read_unlock_bh(&neigh->lock); in neigh_fill_info()
2598 ci.ndm_used = jiffies_to_clock_t(now - neigh->used); in neigh_fill_info()
2599 ci.ndm_confirmed = jiffies_to_clock_t(now - neigh->confirmed); in neigh_fill_info()
2600 ci.ndm_updated = jiffies_to_clock_t(now - neigh->updated); in neigh_fill_info()
2601 ci.ndm_refcnt = refcount_read(&neigh->refcnt) - 1; in neigh_fill_info()
2602 read_unlock_bh(&neigh->lock); in neigh_fill_info()
2604 if (nla_put_u32(skb, NDA_PROBES, atomic_read(&neigh->probes)) || in neigh_fill_info()
2608 if (neigh->protocol && nla_put_u8(skb, NDA_PROTOCOL, neigh->protocol)) in neigh_fill_info()
2661 static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid) in neigh_update_notify() argument
2663 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh); in neigh_update_notify()
2664 __neigh_notify(neigh, RTM_NEWNEIGH, 0, nlmsg_pid); in neigh_update_notify()
2971 static int neigh_get_reply(struct net *net, struct neighbour *neigh, in neigh_get_reply() argument
2981 err = neigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0); in neigh_get_reply()
3000 static int pneigh_get_reply(struct net *net, struct pneigh_entry *neigh, in pneigh_get_reply() argument
3010 err = pneigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0, tbl); in pneigh_get_reply()
3027 struct neighbour *neigh; in neigh_get() local
3068 neigh = neigh_lookup(tbl, dst, dev); in neigh_get()
3069 if (!neigh) { in neigh_get()
3074 err = neigh_get_reply(net, neigh, NETLINK_CB(in_skb).portid, in neigh_get()
3077 neigh_release(neigh); in neigh_get()
3145 struct neighbour *neigh; in neigh_xmit() local
3154 neigh = __ipv4_neigh_lookup_noref(dev, key); in neigh_xmit()
3156 neigh = __neigh_lookup_noref(tbl, addr, dev); in neigh_xmit()
3158 if (!neigh) in neigh_xmit()
3159 neigh = __neigh_create(tbl, addr, dev, false); in neigh_xmit()
3160 err = PTR_ERR(neigh); in neigh_xmit()
3161 if (IS_ERR(neigh)) { in neigh_xmit()
3165 err = neigh->output(neigh, skb); in neigh_xmit()