Lines Matching defs:neigh

42 #include <trace/events/neigh.h>
56 static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid);
77 - with rwlock neigh->lock
81 neigh->lock mainly serializes ll address data and its validity state.
86 Again, nothing clever shall be made under neigh->lock,
92 static int neigh_blackhole(struct neighbour *neigh, struct sk_buff *skb)
98 static void neigh_cleanup_and_release(struct neighbour *neigh)
100 trace_neigh_cleanup_and_release(neigh, 0);
101 __neigh_notify(neigh, RTM_DELNEIGH, 0, 0);
102 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh);
103 neigh_release(neigh);
179 static void neigh_update_flags(struct neighbour *neigh, u32 flags, int *notify,
182 u32 ndm_flags, old_flags = neigh->flags;
192 neigh->flags |= NTF_EXT_LEARNED;
194 neigh->flags &= ~NTF_EXT_LEARNED;
200 neigh->flags |= NTF_MANAGED;
202 neigh->flags &= ~NTF_MANAGED;
215 struct neighbour *neigh;
217 neigh = rcu_dereference_protected(n->next,
219 rcu_assign_pointer(*np, neigh);
426 neigh_dbg(2, "neigh %p is stray\n", n);
721 neigh_dbg(2, "neigh %p is created\n", n);
891 void neigh_destroy(struct neighbour *neigh)
893 struct net_device *dev = neigh->dev;
895 NEIGH_CACHE_STAT_INC(neigh->tbl, destroys);
897 if (!neigh->dead) {
898 pr_warn("Destroying alive neighbour %p\n", neigh);
903 if (neigh_del_timer(neigh))
906 write_lock_bh(&neigh->lock);
907 __skb_queue_purge(&neigh->arp_queue);
908 write_unlock_bh(&neigh->lock);
909 neigh->arp_queue_len_bytes = 0;
912 dev->netdev_ops->ndo_neigh_destroy(dev, neigh);
914 netdev_put(dev, &neigh->dev_tracker);
915 neigh_parms_put(neigh->parms);
917 neigh_dbg(2, "neigh %p is destroyed\n", neigh);
919 atomic_dec(&neigh->tbl->entries);
920 kfree_rcu(neigh, rcu);
927 Called with write_locked neigh.
929 static void neigh_suspect(struct neighbour *neigh)
931 neigh_dbg(2, "neigh %p is suspected\n", neigh);
933 WRITE_ONCE(neigh->output, neigh->ops->output);
939 Called with write_locked neigh.
941 static void neigh_connect(struct neighbour *neigh)
943 neigh_dbg(2, "neigh %p is connected\n", neigh);
945 WRITE_ONCE(neigh->output, neigh->ops->connected_output);
1043 static void neigh_invalidate(struct neighbour *neigh)
1044 __releases(neigh->lock)
1045 __acquires(neigh->lock)
1049 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed);
1050 neigh_dbg(2, "neigh %p is failed\n", neigh);
1051 neigh->updated = jiffies;
1058 while (neigh->nud_state == NUD_FAILED &&
1059 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
1060 write_unlock(&neigh->lock);
1061 neigh->ops->error_report(neigh, skb);
1062 write_lock(&neigh->lock);
1064 __skb_queue_purge(&neigh->arp_queue);
1065 neigh->arp_queue_len_bytes = 0;
1068 static void neigh_probe(struct neighbour *neigh)
1069 __releases(neigh->lock)
1071 struct sk_buff *skb = skb_peek_tail(&neigh->arp_queue);
1075 write_unlock(&neigh->lock);
1076 if (neigh->ops->solicit)
1077 neigh->ops->solicit(neigh, skb);
1078 atomic_inc(&neigh->probes);
1087 struct neighbour *neigh = from_timer(neigh, t, timer);
1091 write_lock(&neigh->lock);
1093 state = neigh->nud_state;
1102 neigh->confirmed + neigh->parms->reachable_time)) {
1103 neigh_dbg(2, "neigh %p is still alive\n", neigh);
1104 next = neigh->confirmed + neigh->parms->reachable_time;
1106 neigh->used +
1107 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
1108 neigh_dbg(2, "neigh %p is delayed\n", neigh);
1109 WRITE_ONCE(neigh->nud_state, NUD_DELAY);
1110 neigh->updated = jiffies;
1111 neigh_suspect(neigh);
1112 next = now + NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME);
1114 neigh_dbg(2, "neigh %p is suspected\n", neigh);
1115 WRITE_ONCE(neigh->nud_state, NUD_STALE);
1116 neigh->updated = jiffies;
1117 neigh_suspect(neigh);
1122 neigh->confirmed +
1123 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
1124 neigh_dbg(2, "neigh %p is now reachable\n", neigh);
1125 WRITE_ONCE(neigh->nud_state, NUD_REACHABLE);
1126 neigh->updated = jiffies;
1127 neigh_connect(neigh);
1129 next = neigh->confirmed + neigh->parms->reachable_time;
1131 neigh_dbg(2, "neigh %p is probed\n", neigh);
1132 WRITE_ONCE(neigh->nud_state, NUD_PROBE);
1133 neigh->updated = jiffies;
1134 atomic_set(&neigh->probes, 0);
1136 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
1141 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), HZ/100);
1144 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) &&
1145 atomic_read(&neigh->probes) >= neigh_max_probes(neigh)) {
1146 WRITE_ONCE(neigh->nud_state, NUD_FAILED);
1148 neigh_invalidate(neigh);
1152 if (neigh->nud_state & NUD_IN_TIMER) {
1155 if (!mod_timer(&neigh->timer, next))
1156 neigh_hold(neigh);
1158 if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {
1159 neigh_probe(neigh);
1162 write_unlock(&neigh->lock);
1166 neigh_update_notify(neigh, 0);
1168 trace_neigh_timer_handler(neigh, 0);
1170 neigh_release(neigh);
1173 int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,
1179 write_lock_bh(&neigh->lock);
1182 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))
1184 if (neigh->dead)
1187 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
1188 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) +
1189 NEIGH_VAR(neigh->parms, APP_PROBES)) {
1192 atomic_set(&neigh->probes,
1193 NEIGH_VAR(neigh->parms, UCAST_PROBES));
1194 neigh_del_timer(neigh);
1195 WRITE_ONCE(neigh->nud_state, NUD_INCOMPLETE);
1196 neigh->updated = now;
1201 next = now + max(NEIGH_VAR(neigh->parms,
1205 neigh_add_timer(neigh, next);
1207 WRITE_ONCE(neigh->nud_state, NUD_FAILED);
1208 neigh->updated = jiffies;
1209 write_unlock_bh(&neigh->lock);
1214 } else if (neigh->nud_state & NUD_STALE) {
1215 neigh_dbg(2, "neigh %p is delayed\n", neigh);
1216 neigh_del_timer(neigh);
1217 WRITE_ONCE(neigh->nud_state, NUD_DELAY);
1218 neigh->updated = jiffies;
1219 neigh_add_timer(neigh, jiffies +
1220 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME));
1223 if (neigh->nud_state == NUD_INCOMPLETE) {
1225 while (neigh->arp_queue_len_bytes + skb->truesize >
1226 NEIGH_VAR(neigh->parms, QUEUE_LEN_BYTES)) {
1229 buff = __skb_dequeue(&neigh->arp_queue);
1232 neigh->arp_queue_len_bytes -= buff->truesize;
1234 NEIGH_CACHE_STAT_INC(neigh->tbl, unres_discards);
1237 __skb_queue_tail(&neigh->arp_queue, skb);
1238 neigh->arp_queue_len_bytes += skb->truesize;
1244 neigh_probe(neigh);
1246 write_unlock(&neigh->lock);
1248 trace_neigh_event_send_done(neigh, rc);
1252 if (neigh->nud_state & NUD_STALE)
1254 write_unlock_bh(&neigh->lock);
1256 trace_neigh_event_send_dead(neigh, 1);
1261 static void neigh_update_hhs(struct neighbour *neigh)
1267 if (neigh->dev->header_ops)
1268 update = neigh->dev->header_ops->cache_update;
1271 hh = &neigh->hh;
1274 update(hh, neigh->dev, neigh->ha);
1299 static int __neigh_update(struct neighbour *neigh, const u8 *lladdr,
1309 trace_neigh_update(neigh, lladdr, new, flags, nlmsg_pid);
1311 write_lock_bh(&neigh->lock);
1313 dev = neigh->dev;
1314 old = neigh->nud_state;
1317 if (neigh->dead) {
1326 neigh_update_flags(neigh, flags, &notify, &gc_update, &managed_update);
1329 WRITE_ONCE(neigh->nud_state, new);
1335 neigh_del_timer(neigh);
1337 neigh_suspect(neigh);
1338 WRITE_ONCE(neigh->nud_state, new);
1343 neigh_invalidate(neigh);
1352 lladdr = neigh->ha;
1360 !memcmp(lladdr, neigh->ha, dev->addr_len))
1361 lladdr = neigh->ha;
1371 lladdr = neigh->ha;
1378 neigh->confirmed = jiffies;
1386 if (lladdr != neigh->ha && !(flags & NEIGH_UPDATE_F_OVERRIDE)) {
1390 lladdr = neigh->ha;
1395 if (lladdr == neigh->ha && new == NUD_STALE &&
1405 if (new != old || lladdr != neigh->ha)
1406 neigh->updated = jiffies;
1409 neigh_del_timer(neigh);
1411 atomic_set(&neigh->probes, 0);
1413 neigh_add_timer(neigh, (jiffies +
1415 neigh->parms->reachable_time :
1417 WRITE_ONCE(neigh->nud_state, new);
1421 if (lladdr != neigh->ha) {
1422 write_seqlock(&neigh->ha_lock);
1423 memcpy(&neigh->ha, lladdr, dev->addr_len);
1424 write_sequnlock(&neigh->ha_lock);
1425 neigh_update_hhs(neigh);
1427 neigh->confirmed = jiffies -
1428 (NEIGH_VAR(neigh->parms, BASE_REACHABLE_TIME) << 1);
1434 neigh_connect(neigh);
1436 neigh_suspect(neigh);
1442 while (neigh->nud_state & NUD_VALID &&
1443 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
1445 struct neighbour *n2, *n1 = neigh;
1446 write_unlock_bh(&neigh->lock);
1450 /* Why not just use 'neigh' as-is? The problem is that
1452 * using alternative, different, neigh objects to output
1454 * here is re-lookup the top-level neigh in the path so
1468 write_lock_bh(&neigh->lock);
1470 __skb_queue_purge(&neigh->arp_queue);
1471 neigh->arp_queue_len_bytes = 0;
1475 neigh_update_is_router(neigh, flags, &notify);
1476 write_unlock_bh(&neigh->lock);
1478 neigh_update_gc_list(neigh);
1480 neigh_update_managed_list(neigh);
1482 neigh_update_notify(neigh, nlmsg_pid);
1483 trace_neigh_update_done(neigh, err);
1487 int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1490 return __neigh_update(neigh, lladdr, new, flags, nlmsg_pid, NULL);
1494 /* Update the neigh to listen temporarily for probe responses, even if it is
1495 * in a NUD_FAILED state. The caller has to hold neigh->lock for writing.
1497 void __neigh_set_probe_once(struct neighbour *neigh)
1499 if (neigh->dead)
1501 neigh->updated = jiffies;
1502 if (!(neigh->nud_state & NUD_FAILED))
1504 WRITE_ONCE(neigh->nud_state, NUD_INCOMPLETE);
1505 atomic_set(&neigh->probes, neigh_max_probes(neigh));
1506 neigh_add_timer(neigh,
1507 jiffies + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
1516 struct neighbour *neigh = __neigh_lookup(tbl, saddr, dev,
1518 if (neigh)
1519 neigh_update(neigh, lladdr, NUD_STALE,
1521 return neigh;
1545 int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)
1549 if (!neigh_event_send(neigh, skb)) {
1551 struct net_device *dev = neigh->dev;
1554 if (dev->header_ops->cache && !READ_ONCE(neigh->hh.hh_len))
1555 neigh_hh_init(neigh);
1559 seq = read_seqbegin(&neigh->ha_lock);
1561 neigh->ha, NULL, skb->len);
1562 } while (read_seqretry(&neigh->ha_lock, seq));
1580 int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb)
1582 struct net_device *dev = neigh->dev;
1588 seq = read_seqbegin(&neigh->ha_lock);
1590 neigh->ha, NULL, skb->len);
1591 } while (read_seqretry(&neigh->ha_lock, seq));
1603 int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb)
1613 struct neighbour *neigh;
1616 list_for_each_entry(neigh, &tbl->managed_list, managed_list)
1617 neigh_event_send_probe(neigh, NULL, false);
1909 struct neighbour *neigh;
1949 neigh = neigh_lookup(tbl, nla_data(dst_attr), dev);
1950 if (neigh == NULL) {
1955 err = __neigh_update(neigh, NULL, NUD_FAILED,
1959 neigh_release(neigh);
1960 neigh_remove_one(neigh, tbl);
1977 struct neighbour *neigh;
2000 BUILD_BUG_ON(sizeof(neigh->flags) * BITS_PER_BYTE <
2061 neigh = neigh_lookup(tbl, dst, dev);
2062 if (neigh == NULL) {
2077 neigh = ___neigh_create(tbl, dst, dev,
2081 if (IS_ERR(neigh)) {
2082 err = PTR_ERR(neigh);
2088 neigh_release(neigh);
2098 neigh->protocol = protocol;
2108 err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags,
2111 neigh_event_send(neigh, NULL);
2114 neigh_release(neigh);
2570 static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh,
2583 neigh_flags_ext = neigh->flags >> NTF_EXT_SHIFT;
2584 neigh_flags = neigh->flags & NTF_OLD_MASK;
2587 ndm->ndm_family = neigh->ops->family;
2591 ndm->ndm_type = neigh->type;
2592 ndm->ndm_ifindex = neigh->dev->ifindex;
2594 if (nla_put(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key))
2597 read_lock_bh(&neigh->lock);
2598 ndm->ndm_state = neigh->nud_state;
2599 if (neigh->nud_state & NUD_VALID) {
2602 neigh_ha_snapshot(haddr, neigh, neigh->dev);
2603 if (nla_put(skb, NDA_LLADDR, neigh->dev->addr_len, haddr) < 0) {
2604 read_unlock_bh(&neigh->lock);
2609 ci.ndm_used = jiffies_to_clock_t(now - neigh->used);
2610 ci.ndm_confirmed = jiffies_to_clock_t(now - neigh->confirmed);
2611 ci.ndm_updated = jiffies_to_clock_t(now - neigh->updated);
2612 ci.ndm_refcnt = refcount_read(&neigh->refcnt) - 1;
2613 read_unlock_bh(&neigh->lock);
2615 if (nla_put_u32(skb, NDA_PROBES, atomic_read(&neigh->probes)) ||
2619 if (neigh->protocol && nla_put_u8(skb, NDA_PROTOCOL, neigh->protocol))
2672 static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid)
2674 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh);
2675 __neigh_notify(neigh, RTM_NEWNEIGH, 0, nlmsg_pid);
2977 static int neigh_get_reply(struct net *net, struct neighbour *neigh,
2987 err = neigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0);
3006 static int pneigh_get_reply(struct net *net, struct pneigh_entry *neigh,
3016 err = pneigh_fill_info(skb, neigh, pid, seq, RTM_NEWNEIGH, 0, tbl);
3033 struct neighbour *neigh;
3074 neigh = neigh_lookup(tbl, dst, dev);
3075 if (!neigh) {
3080 err = neigh_get_reply(net, neigh, NETLINK_CB(in_skb).portid,
3083 neigh_release(neigh);
3152 struct neighbour *neigh;
3161 neigh = __ipv4_neigh_lookup_noref(dev, key);
3163 neigh = __neigh_lookup_noref(tbl, addr, dev);
3165 if (!neigh)
3166 neigh = __neigh_create(tbl, addr, dev, false);
3167 err = PTR_ERR(neigh);
3168 if (IS_ERR(neigh)) {
3172 err = READ_ONCE(neigh->output)(neigh, skb);
3796 char neigh_path[ sizeof("net//neigh/") + IFNAMSIZ + IFNAMSIZ ];
3859 snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s",