Lines Matching refs:neigh
42 #include <trace/events/neigh.h>
57 static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid);
78 - with rwlock neigh->lock
82 neigh->lock mainly serializes ll address data and its validity state.
87 Again, nothing clever shall be made under neigh->lock,
93 static int neigh_blackhole(struct neighbour *neigh, struct sk_buff *skb)
99 static void neigh_cleanup_and_release(struct neighbour *neigh)
101 trace_neigh_cleanup_and_release(neigh, 0);
102 __neigh_notify(neigh, RTM_DELNEIGH, 0, 0);
103 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh);
104 neigh_release(neigh);
159 static bool neigh_update_ext_learned(struct neighbour *neigh, u32 flags,
169 if ((neigh->flags ^ ndm_flags) & NTF_EXT_LEARNED) {
171 neigh->flags |= NTF_EXT_LEARNED;
173 neigh->flags &= ~NTF_EXT_LEARNED;
188 struct neighbour *neigh;
190 neigh = rcu_dereference_protected(n->next,
192 rcu_assign_pointer(*np, neigh);
372 neigh_dbg(2, "neigh %p is stray\n", n);
664 neigh_dbg(2, "neigh %p is created\n", n);
836 void neigh_destroy(struct neighbour *neigh)
838 struct net_device *dev = neigh->dev;
840 NEIGH_CACHE_STAT_INC(neigh->tbl, destroys);
842 if (!neigh->dead) {
843 pr_warn("Destroying alive neighbour %p\n", neigh);
848 if (neigh_del_timer(neigh))
851 write_lock_bh(&neigh->lock);
852 __skb_queue_purge(&neigh->arp_queue);
853 write_unlock_bh(&neigh->lock);
854 neigh->arp_queue_len_bytes = 0;
857 dev->netdev_ops->ndo_neigh_destroy(dev, neigh);
860 neigh_parms_put(neigh->parms);
862 neigh_dbg(2, "neigh %p is destroyed\n", neigh);
864 atomic_dec(&neigh->tbl->entries);
865 kfree_rcu(neigh, rcu);
872 Called with write_locked neigh.
874 static void neigh_suspect(struct neighbour *neigh)
876 neigh_dbg(2, "neigh %p is suspected\n", neigh);
878 neigh->output = neigh->ops->output;
884 Called with write_locked neigh.
886 static void neigh_connect(struct neighbour *neigh)
888 neigh_dbg(2, "neigh %p is connected\n", neigh);
890 neigh->output = neigh->ops->connected_output;
988 static void neigh_invalidate(struct neighbour *neigh)
989 __releases(neigh->lock)
990 __acquires(neigh->lock)
994 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed);
995 neigh_dbg(2, "neigh %p is failed\n", neigh);
996 neigh->updated = jiffies;
1003 while (neigh->nud_state == NUD_FAILED &&
1004 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
1005 write_unlock(&neigh->lock);
1006 neigh->ops->error_report(neigh, skb);
1007 write_lock(&neigh->lock);
1009 __skb_queue_purge(&neigh->arp_queue);
1010 neigh->arp_queue_len_bytes = 0;
1013 static void neigh_probe(struct neighbour *neigh)
1014 __releases(neigh->lock)
1016 struct sk_buff *skb = skb_peek_tail(&neigh->arp_queue);
1020 write_unlock(&neigh->lock);
1021 if (neigh->ops->solicit)
1022 neigh->ops->solicit(neigh, skb);
1023 atomic_inc(&neigh->probes);
1032 struct neighbour *neigh = from_timer(neigh, t, timer);
1036 write_lock(&neigh->lock);
1038 state = neigh->nud_state;
1047 neigh->confirmed + neigh->parms->reachable_time)) {
1048 neigh_dbg(2, "neigh %p is still alive\n", neigh);
1049 next = neigh->confirmed + neigh->parms->reachable_time;
1051 neigh->used +
1052 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
1053 neigh_dbg(2, "neigh %p is delayed\n", neigh);
1054 neigh->nud_state = NUD_DELAY;
1055 neigh->updated = jiffies;
1056 neigh_suspect(neigh);
1057 next = now + NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME);
1059 neigh_dbg(2, "neigh %p is suspected\n", neigh);
1060 neigh->nud_state = NUD_STALE;
1061 neigh->updated = jiffies;
1062 neigh_suspect(neigh);
1067 neigh->confirmed +
1068 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
1069 neigh_dbg(2, "neigh %p is now reachable\n", neigh);
1070 neigh->nud_state = NUD_REACHABLE;
1071 neigh->updated = jiffies;
1072 neigh_connect(neigh);
1074 next = neigh->confirmed + neigh->parms->reachable_time;
1076 neigh_dbg(2, "neigh %p is probed\n", neigh);
1077 neigh->nud_state = NUD_PROBE;
1078 neigh->updated = jiffies;
1079 atomic_set(&neigh->probes, 0);
1081 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
1086 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), HZ/100);
1089 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) &&
1090 atomic_read(&neigh->probes) >= neigh_max_probes(neigh)) {
1091 neigh->nud_state = NUD_FAILED;
1093 neigh_invalidate(neigh);
1097 if (neigh->nud_state & NUD_IN_TIMER) {
1100 if (!mod_timer(&neigh->timer, next))
1101 neigh_hold(neigh);
1103 if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {
1104 neigh_probe(neigh);
1107 write_unlock(&neigh->lock);
1111 neigh_update_notify(neigh, 0);
1113 trace_neigh_timer_handler(neigh, 0);
1115 neigh_release(neigh);
1118 int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
1123 write_lock_bh(&neigh->lock);
1126 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))
1128 if (neigh->dead)
1131 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
1132 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) +
1133 NEIGH_VAR(neigh->parms, APP_PROBES)) {
1136 atomic_set(&neigh->probes,
1137 NEIGH_VAR(neigh->parms, UCAST_PROBES));
1138 neigh_del_timer(neigh);
1139 neigh->nud_state = NUD_INCOMPLETE;
1140 neigh->updated = now;
1141 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
1143 neigh_add_timer(neigh, next);
1146 neigh->nud_state = NUD_FAILED;
1147 neigh->updated = jiffies;
1148 write_unlock_bh(&neigh->lock);
1153 } else if (neigh->nud_state & NUD_STALE) {
1154 neigh_dbg(2, "neigh %p is delayed\n", neigh);
1155 neigh_del_timer(neigh);
1156 neigh->nud_state = NUD_DELAY;
1157 neigh->updated = jiffies;
1158 neigh_add_timer(neigh, jiffies +
1159 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME));
1162 if (neigh->nud_state == NUD_INCOMPLETE) {
1164 while (neigh->arp_queue_len_bytes + skb->truesize >
1165 NEIGH_VAR(neigh->parms, QUEUE_LEN_BYTES)) {
1168 buff = __skb_dequeue(&neigh->arp_queue);
1171 neigh->arp_queue_len_bytes -= buff->truesize;
1173 NEIGH_CACHE_STAT_INC(neigh->tbl, unres_discards);
1176 __skb_queue_tail(&neigh->arp_queue, skb);
1177 neigh->arp_queue_len_bytes += skb->truesize;
1183 neigh_probe(neigh);
1185 write_unlock(&neigh->lock);
1187 trace_neigh_event_send_done(neigh, rc);
1191 if (neigh->nud_state & NUD_STALE)
1193 write_unlock_bh(&neigh->lock);
1195 trace_neigh_event_send_dead(neigh, 1);
1200 static void neigh_update_hhs(struct neighbour *neigh)
1206 if (neigh->dev->header_ops)
1207 update = neigh->dev->header_ops->cache_update;
1210 hh = &neigh->hh;
1213 update(hh, neigh->dev, neigh->ha);
1240 static int __neigh_update(struct neighbour *neigh, const u8 *lladdr,
1251 trace_neigh_update(neigh, lladdr, new, flags, nlmsg_pid);
1253 write_lock_bh(&neigh->lock);
1255 dev = neigh->dev;
1256 old = neigh->nud_state;
1259 if (neigh->dead) {
1268 ext_learn_change = neigh_update_ext_learned(neigh, flags, ¬ify);
1271 neigh->nud_state = new;
1277 neigh_del_timer(neigh);
1279 neigh_suspect(neigh);
1280 neigh->nud_state = new;
1285 neigh_invalidate(neigh);
1294 lladdr = neigh->ha;
1302 !memcmp(lladdr, neigh->ha, dev->addr_len))
1303 lladdr = neigh->ha;
1313 lladdr = neigh->ha;
1320 neigh->confirmed = jiffies;
1328 if (lladdr != neigh->ha && !(flags & NEIGH_UPDATE_F_OVERRIDE)) {
1332 lladdr = neigh->ha;
1337 if (lladdr == neigh->ha && new == NUD_STALE &&
1347 if (new != old || lladdr != neigh->ha)
1348 neigh->updated = jiffies;
1351 neigh_del_timer(neigh);
1353 atomic_set(&neigh->probes, 0);
1355 neigh_add_timer(neigh, (jiffies +
1357 neigh->parms->reachable_time :
1359 neigh->nud_state = new;
1363 if (lladdr != neigh->ha) {
1364 write_seqlock(&neigh->ha_lock);
1365 memcpy(&neigh->ha, lladdr, dev->addr_len);
1366 write_sequnlock(&neigh->ha_lock);
1367 neigh_update_hhs(neigh);
1369 neigh->confirmed = jiffies -
1370 (NEIGH_VAR(neigh->parms, BASE_REACHABLE_TIME) << 1);
1376 neigh_connect(neigh);
1378 neigh_suspect(neigh);
1384 while (neigh->nud_state & NUD_VALID &&
1385 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
1387 struct neighbour *n2, *n1 = neigh;
1388 write_unlock_bh(&neigh->lock);
1392 /* Why not just use 'neigh' as-is? The problem is that
1394 * using alternative, different, neigh objects to output
1396 * here is re-lookup the top-level neigh in the path so
1410 write_lock_bh(&neigh->lock);
1412 __skb_queue_purge(&neigh->arp_queue);
1413 neigh->arp_queue_len_bytes = 0;
1417 neigh_update_is_router(neigh, flags, ¬ify);
1418 write_unlock_bh(&neigh->lock);
1421 neigh_update_gc_list(neigh);
1424 neigh_update_notify(neigh, nlmsg_pid);
1426 trace_neigh_update_done(neigh, err);
1431 int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1434 return __neigh_update(neigh, lladdr, new, flags, nlmsg_pid, NULL);
1438 /* Update the neigh to listen temporarily for probe responses, even if it is
1439 * in a NUD_FAILED state. The caller has to hold neigh->lock for writing.
1441 void __neigh_set_probe_once(struct neighbour *neigh)
1443 if (neigh->dead)
1445 neigh->updated = jiffies;
1446 if (!(neigh->nud_state & NUD_FAILED))
1448 neigh->nud_state = NUD_INCOMPLETE;
1449 atomic_set(&neigh->probes, neigh_max_probes(neigh));
1450 neigh_add_timer(neigh,
1451 jiffies + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
1460 struct neighbour *neigh = __neigh_lookup(tbl, saddr, dev,
1462 if (neigh)
1463 neigh_update(neigh, lladdr, NUD_STALE,
1465 return neigh;
1489 int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)
1493 if (!neigh_event_send(neigh, skb)) {
1495 struct net_device *dev = neigh->dev;
1498 if (dev->header_ops->cache && !READ_ONCE(neigh->hh.hh_len))
1499 neigh_hh_init(neigh);
1503 seq = read_seqbegin(&neigh->ha_lock);
1505 neigh->ha, NULL, skb->len);
1506 } while (read_seqretry(&neigh->ha_lock, seq));
1524 int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb)
1526 struct net_device *dev = neigh->dev;
1532 seq = read_seqbegin(&neigh->ha_lock);
1534 neigh->ha, NULL, skb->len);
1535 } while (read_seqretry(&neigh->ha_lock, seq));
1547 int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb)
1818 struct neighbour *neigh;
1858 neigh = neigh_lookup(tbl, nla_data(dst_attr), dev);
1859 if (neigh == NULL) {
1864 err = __neigh_update(neigh, NULL, NUD_FAILED,
1868 neigh_release(neigh);
1869 neigh_remove_one(neigh, tbl);
1886 struct neighbour *neigh;
1956 neigh = neigh_lookup(tbl, dst, dev);
1957 if (neigh == NULL) {
1967 neigh = ___neigh_create(tbl, dst, dev,
1970 if (IS_ERR(neigh)) {
1971 err = PTR_ERR(neigh);
1977 neigh_release(neigh);
1987 neigh->protocol = protocol;
1995 err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags,
1998 neigh_event_send(neigh, NULL);
2001 neigh_release(neigh);
2450 static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh,
2463 ndm->ndm_family = neigh->ops->family;
2466 ndm->ndm_flags = neigh->flags;
2467 ndm->ndm_type = neigh->type;
2468 ndm->ndm_ifindex = neigh->dev->ifindex;
2470 if (nla_put(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key))
2473 read_lock_bh(&neigh->lock);
2474 ndm->ndm_state = neigh->nud_state;
2475 if (neigh->nud_state & NUD_VALID) {
2478 neigh_ha_snapshot(haddr, neigh, neigh->dev);
2479 if (nla_put(skb, NDA_LLADDR, neigh->dev->addr_len, haddr) < 0) {
2480 read_unlock_bh(&neigh->lock);
2485 ci.ndm_used = jiffies_to_clock_t(now - neigh->used);
2486 ci.ndm_confirmed = jiffies_to_clock_t(now - neigh->confirmed);
2487 ci.ndm_updated = jiffies_to_clock_t(now - neigh->updated);
2488 ci.ndm_refcnt = refcount_read(&neigh->refcnt) - 1;
2489 read_unlock_bh(&neigh->lock);
2491 if (nla_put_u32(skb, NDA_PROBES, atomic_read(&neigh->probes)) ||
2495 if (neigh->protocol && nla_put_u8(skb, NDA_PROTOCOL, neigh->protocol))
2540 static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid)
2542 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh);
2543 __neigh_notify(neigh, RTM_NEWNEIGH, 0, nlmsg_pid);
2842 static int neigh_get_reply(struct net *net, struct neighbour *neigh,
2852 err = neigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0);
2870 static int pneigh_get_reply(struct net *net, struct pneigh_entry *neigh,
2880 err = pneigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0, tbl);
2897 struct neighbour *neigh;
2938 neigh = neigh_lookup(tbl, dst, dev);
2939 if (!neigh) {
2944 err = neigh_get_reply(net, neigh, NETLINK_CB(in_skb).portid,
2947 neigh_release(neigh);
3015 struct neighbour *neigh;
3024 neigh = __ipv4_neigh_lookup_noref(dev, key);
3026 neigh = __neigh_lookup_noref(tbl, addr, dev);
3028 if (!neigh)
3029 neigh = __neigh_create(tbl, addr, dev, false);
3030 err = PTR_ERR(neigh);
3031 if (IS_ERR(neigh)) {
3035 err = neigh->output(neigh, skb);
3649 char neigh_path[ sizeof("net//neigh/") + IFNAMSIZ + IFNAMSIZ ];
3715 snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s",