11da177e4SLinus Torvalds #ifndef _NET_NEIGHBOUR_H 21da177e4SLinus Torvalds #define _NET_NEIGHBOUR_H 31da177e4SLinus Torvalds 49067c722SThomas Graf #include <linux/neighbour.h> 59067c722SThomas Graf 61da177e4SLinus Torvalds /* 71da177e4SLinus Torvalds * Generic neighbour manipulation 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Authors: 101da177e4SLinus Torvalds * Pedro Roque <roque@di.fc.ul.pt> 111da177e4SLinus Torvalds * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * Changes: 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * Harald Welte: <laforge@gnumonks.org> 161da177e4SLinus Torvalds * - Add neighbour cache statistics like rtstat 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds 1960063497SArun Sharma #include <linux/atomic.h> 201da177e4SLinus Torvalds #include <linux/netdevice.h> 2114c85021SArnaldo Carvalho de Melo #include <linux/skbuff.h> 221da177e4SLinus Torvalds #include <linux/rcupdate.h> 231da177e4SLinus Torvalds #include <linux/seq_file.h> 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <linux/err.h> 261da177e4SLinus Torvalds #include <linux/sysctl.h> 27e4c4e448SEric Dumazet #include <linux/workqueue.h> 28c8822a4eSThomas Graf #include <net/rtnetlink.h> 291da177e4SLinus Torvalds 3039971554SPavel Emelyanov /* 3139971554SPavel Emelyanov * NUD stands for "neighbor unreachability detection" 3239971554SPavel Emelyanov */ 3339971554SPavel Emelyanov 341da177e4SLinus Torvalds #define NUD_IN_TIMER (NUD_INCOMPLETE|NUD_REACHABLE|NUD_DELAY|NUD_PROBE) 351da177e4SLinus Torvalds #define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY) 361da177e4SLinus Torvalds #define NUD_CONNECTED (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE) 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds struct neighbour; 391da177e4SLinus Torvalds 401f9248e5SJiri Pirko enum { 411f9248e5SJiri Pirko NEIGH_VAR_MCAST_PROBES, 421f9248e5SJiri Pirko NEIGH_VAR_UCAST_PROBES, 431f9248e5SJiri Pirko NEIGH_VAR_APP_PROBES, 441f9248e5SJiri Pirko NEIGH_VAR_RETRANS_TIME, 451f9248e5SJiri Pirko NEIGH_VAR_BASE_REACHABLE_TIME, 461f9248e5SJiri Pirko NEIGH_VAR_DELAY_PROBE_TIME, 471f9248e5SJiri Pirko NEIGH_VAR_GC_STALETIME, 481f9248e5SJiri Pirko NEIGH_VAR_QUEUE_LEN_BYTES, 491f9248e5SJiri Pirko NEIGH_VAR_PROXY_QLEN, 501f9248e5SJiri Pirko NEIGH_VAR_ANYCAST_DELAY, 511f9248e5SJiri Pirko NEIGH_VAR_PROXY_DELAY, 521f9248e5SJiri Pirko NEIGH_VAR_LOCKTIME, 531f9248e5SJiri Pirko #define NEIGH_VAR_DATA_MAX (NEIGH_VAR_LOCKTIME + 1) 541f9248e5SJiri Pirko /* Following are used as a second way to access one of the above */ 551f9248e5SJiri Pirko NEIGH_VAR_QUEUE_LEN, /* same data as NEIGH_VAR_QUEUE_LEN_BYTES */ 561f9248e5SJiri Pirko NEIGH_VAR_RETRANS_TIME_MS, /* same data as NEIGH_VAR_RETRANS_TIME */ 571f9248e5SJiri Pirko NEIGH_VAR_BASE_REACHABLE_TIME_MS, /* same data as NEIGH_VAR_BASE_REACHABLE_TIME */ 581f9248e5SJiri Pirko /* Following are used by "default" only */ 591f9248e5SJiri Pirko NEIGH_VAR_GC_INTERVAL, 601f9248e5SJiri Pirko NEIGH_VAR_GC_THRESH1, 611f9248e5SJiri Pirko NEIGH_VAR_GC_THRESH2, 621f9248e5SJiri Pirko NEIGH_VAR_GC_THRESH3, 631f9248e5SJiri Pirko NEIGH_VAR_MAX 641f9248e5SJiri Pirko }; 651f9248e5SJiri Pirko 66fd2c3ef7SEric Dumazet struct neigh_parms { 6757da52c1SYOSHIFUJI Hideaki #ifdef CONFIG_NET_NS 68426b5303SEric W. Biederman struct net *net; 6957da52c1SYOSHIFUJI Hideaki #endif 70c7fb64dbSThomas Graf struct net_device *dev; 711da177e4SLinus Torvalds struct neigh_parms *next; 72447f2191SDavid S. Miller int (*neigh_setup)(struct neighbour *); 73ecbb4169SAlexey Kuznetsov void (*neigh_cleanup)(struct neighbour *); 741da177e4SLinus Torvalds struct neigh_table *tbl; 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds void *sysctl_table; 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds int dead; 791da177e4SLinus Torvalds atomic_t refcnt; 801da177e4SLinus Torvalds struct rcu_head rcu_head; 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds int reachable_time; 831f9248e5SJiri Pirko int data[NEIGH_VAR_DATA_MAX]; 841da177e4SLinus Torvalds }; 851da177e4SLinus Torvalds 861f9248e5SJiri Pirko static inline void neigh_var_set(struct neigh_parms *p, int index, int val) 871f9248e5SJiri Pirko { 881f9248e5SJiri Pirko p->data[index] = val; 891f9248e5SJiri Pirko } 901f9248e5SJiri Pirko 911f9248e5SJiri Pirko #define NEIGH_VAR(p, attr) ((p)->data[NEIGH_VAR_ ## attr]) 921f9248e5SJiri Pirko #define NEIGH_VAR_SET(p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val) 931f9248e5SJiri Pirko 94fd2c3ef7SEric Dumazet struct neigh_statistics { 951da177e4SLinus Torvalds unsigned long allocs; /* number of allocated neighs */ 961da177e4SLinus Torvalds unsigned long destroys; /* number of destroyed neighs */ 971da177e4SLinus Torvalds unsigned long hash_grows; /* number of hash resizes */ 981da177e4SLinus Torvalds 999a6d276eSNeil Horman unsigned long res_failed; /* number of failed resolutions */ 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds unsigned long lookups; /* number of lookups */ 1021da177e4SLinus Torvalds unsigned long hits; /* number of hits (among lookups) */ 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds unsigned long rcv_probes_mcast; /* number of received mcast ipv6 */ 1051da177e4SLinus Torvalds unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */ 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds unsigned long periodic_gc_runs; /* number of periodic GC runs */ 1081da177e4SLinus Torvalds unsigned long forced_gc_runs; /* number of forced GC runs */ 1099a6d276eSNeil Horman 1109a6d276eSNeil Horman unsigned long unres_discards; /* number of unresolved drops */ 1111da177e4SLinus Torvalds }; 1121da177e4SLinus Torvalds 1134ea7334bSChristoph Lameter #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field) 1141da177e4SLinus Torvalds 115fd2c3ef7SEric Dumazet struct neighbour { 116767e97e1SEric Dumazet struct neighbour __rcu *next; 1171da177e4SLinus Torvalds struct neigh_table *tbl; 1181da177e4SLinus Torvalds struct neigh_parms *parms; 1191da177e4SLinus Torvalds unsigned long confirmed; 1201da177e4SLinus Torvalds unsigned long updated; 12146b13fc5SEric Dumazet rwlock_t lock; 122367e5e37SEric Dumazet atomic_t refcnt; 123e37ef961SEric Dumazet struct sk_buff_head arp_queue; 1248b5c171bSEric Dumazet unsigned int arp_queue_len_bytes; 125e37ef961SEric Dumazet struct timer_list timer; 126e37ef961SEric Dumazet unsigned long used; 1271da177e4SLinus Torvalds atomic_t probes; 12846b13fc5SEric Dumazet __u8 flags; 12946b13fc5SEric Dumazet __u8 nud_state; 13046b13fc5SEric Dumazet __u8 type; 13146b13fc5SEric Dumazet __u8 dead; 1320ed8ddf4SEric Dumazet seqlock_t ha_lock; 133d924424aSStephen Hemminger unsigned char ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))]; 134f6b72b62SDavid S. Miller struct hh_cache hh; 1358f40b161SDavid S. Miller int (*output)(struct neighbour *, struct sk_buff *); 13689d69d2bSStephen Hemminger const struct neigh_ops *ops; 137767e97e1SEric Dumazet struct rcu_head rcu; 138e37ef961SEric Dumazet struct net_device *dev; 1391da177e4SLinus Torvalds u8 primary_key[0]; 1401da177e4SLinus Torvalds }; 1411da177e4SLinus Torvalds 142fd2c3ef7SEric Dumazet struct neigh_ops { 1431da177e4SLinus Torvalds int family; 1441da177e4SLinus Torvalds void (*solicit)(struct neighbour *, struct sk_buff *); 1451da177e4SLinus Torvalds void (*error_report)(struct neighbour *, struct sk_buff *); 1468f40b161SDavid S. Miller int (*output)(struct neighbour *, struct sk_buff *); 1478f40b161SDavid S. Miller int (*connected_output)(struct neighbour *, struct sk_buff *); 1481da177e4SLinus Torvalds }; 1491da177e4SLinus Torvalds 150fd2c3ef7SEric Dumazet struct pneigh_entry { 1511da177e4SLinus Torvalds struct pneigh_entry *next; 15257da52c1SYOSHIFUJI Hideaki #ifdef CONFIG_NET_NS 153426b5303SEric W. Biederman struct net *net; 15457da52c1SYOSHIFUJI Hideaki #endif 1551da177e4SLinus Torvalds struct net_device *dev; 15662dd9318SVille Nuorvala u8 flags; 1571da177e4SLinus Torvalds u8 key[0]; 1581da177e4SLinus Torvalds }; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds /* 1611da177e4SLinus Torvalds * neighbour table manipulation 1621da177e4SLinus Torvalds */ 1631da177e4SLinus Torvalds 1642c2aba6cSDavid S. Miller #define NEIGH_NUM_HASH_RND 4 1652c2aba6cSDavid S. Miller 166d6bf7817SEric Dumazet struct neigh_hash_table { 167767e97e1SEric Dumazet struct neighbour __rcu **hash_buckets; 168cd089336SDavid S. Miller unsigned int hash_shift; 1692c2aba6cSDavid S. Miller __u32 hash_rnd[NEIGH_NUM_HASH_RND]; 170d6bf7817SEric Dumazet struct rcu_head rcu; 171d6bf7817SEric Dumazet }; 172d6bf7817SEric Dumazet 1731da177e4SLinus Torvalds 174fd2c3ef7SEric Dumazet struct neigh_table { 1751da177e4SLinus Torvalds struct neigh_table *next; 1761da177e4SLinus Torvalds int family; 1771da177e4SLinus Torvalds int entry_size; 1781da177e4SLinus Torvalds int key_len; 179d6bf7817SEric Dumazet __u32 (*hash)(const void *pkey, 180d6bf7817SEric Dumazet const struct net_device *dev, 1812c2aba6cSDavid S. Miller __u32 *hash_rnd); 1821da177e4SLinus Torvalds int (*constructor)(struct neighbour *); 1831da177e4SLinus Torvalds int (*pconstructor)(struct pneigh_entry *); 1841da177e4SLinus Torvalds void (*pdestructor)(struct pneigh_entry *); 1851da177e4SLinus Torvalds void (*proxy_redo)(struct sk_buff *skb); 1861da177e4SLinus Torvalds char *id; 1871da177e4SLinus Torvalds struct neigh_parms parms; 188787a3445SKulikov Vasiliy /* HACK. gc_* should follow parms without a gap! */ 1891da177e4SLinus Torvalds int gc_interval; 1901da177e4SLinus Torvalds int gc_thresh1; 1911da177e4SLinus Torvalds int gc_thresh2; 1921da177e4SLinus Torvalds int gc_thresh3; 1931da177e4SLinus Torvalds unsigned long last_flush; 194e4c4e448SEric Dumazet struct delayed_work gc_work; 1951da177e4SLinus Torvalds struct timer_list proxy_timer; 1961da177e4SLinus Torvalds struct sk_buff_head proxy_queue; 1971da177e4SLinus Torvalds atomic_t entries; 1981da177e4SLinus Torvalds rwlock_t lock; 1991da177e4SLinus Torvalds unsigned long last_rand; 2007d720c3eSTejun Heo struct neigh_statistics __percpu *stats; 201d6bf7817SEric Dumazet struct neigh_hash_table __rcu *nht; 2021da177e4SLinus Torvalds struct pneigh_entry **phash_buckets; 2031da177e4SLinus Torvalds }; 2041da177e4SLinus Torvalds 2051026fec8SDavid Miller #define NEIGH_PRIV_ALIGN sizeof(long long) 206daaba4faSYOSHIFUJI Hideaki / 吉藤英明 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN) 2071026fec8SDavid Miller 2081026fec8SDavid Miller static inline void *neighbour_priv(const struct neighbour *n) 2091026fec8SDavid Miller { 21008433effSYOSHIFUJI Hideaki / 吉藤英明 return (char *)n + n->tbl->entry_size; 2111026fec8SDavid Miller } 2121026fec8SDavid Miller 2131da177e4SLinus Torvalds /* flags for neigh_update() */ 2141da177e4SLinus Torvalds #define NEIGH_UPDATE_F_OVERRIDE 0x00000001 2151da177e4SLinus Torvalds #define NEIGH_UPDATE_F_WEAK_OVERRIDE 0x00000002 2161da177e4SLinus Torvalds #define NEIGH_UPDATE_F_OVERRIDE_ISROUTER 0x00000004 2171da177e4SLinus Torvalds #define NEIGH_UPDATE_F_ISROUTER 0x40000000 2181da177e4SLinus Torvalds #define NEIGH_UPDATE_F_ADMIN 0x80000000 2191da177e4SLinus Torvalds 22090972b22SJoe Perches void neigh_table_init(struct neigh_table *tbl); 22190972b22SJoe Perches int neigh_table_clear(struct neigh_table *tbl); 22290972b22SJoe Perches struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey, 2231da177e4SLinus Torvalds struct net_device *dev); 22490972b22SJoe Perches struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, struct net *net, 2251da177e4SLinus Torvalds const void *pkey); 22690972b22SJoe Perches struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey, 22790972b22SJoe Perches struct net_device *dev, bool want_ref); 228a263b309SDavid S. Miller static inline struct neighbour *neigh_create(struct neigh_table *tbl, 229a263b309SDavid S. Miller const void *pkey, 230a263b309SDavid S. Miller struct net_device *dev) 231a263b309SDavid S. Miller { 232a263b309SDavid S. Miller return __neigh_create(tbl, pkey, dev, true); 233a263b309SDavid S. Miller } 23490972b22SJoe Perches void neigh_destroy(struct neighbour *neigh); 23590972b22SJoe Perches int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb); 23690972b22SJoe Perches int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, u32 flags); 23790972b22SJoe Perches void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev); 23890972b22SJoe Perches int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev); 23990972b22SJoe Perches int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb); 24090972b22SJoe Perches int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb); 24190972b22SJoe Perches int neigh_compat_output(struct neighbour *neigh, struct sk_buff *skb); 24290972b22SJoe Perches int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb); 24390972b22SJoe Perches struct neighbour *neigh_event_ns(struct neigh_table *tbl, 2441da177e4SLinus Torvalds u8 *lladdr, void *saddr, 2451da177e4SLinus Torvalds struct net_device *dev); 2461da177e4SLinus Torvalds 24790972b22SJoe Perches struct neigh_parms *neigh_parms_alloc(struct net_device *dev, 24890972b22SJoe Perches struct neigh_table *tbl); 24990972b22SJoe Perches void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms); 25057da52c1SYOSHIFUJI Hideaki 25157da52c1SYOSHIFUJI Hideaki static inline 25257da52c1SYOSHIFUJI Hideaki struct net *neigh_parms_net(const struct neigh_parms *parms) 25357da52c1SYOSHIFUJI Hideaki { 254e42ea986SEric Dumazet return read_pnet(&parms->net); 25557da52c1SYOSHIFUJI Hideaki } 25657da52c1SYOSHIFUJI Hideaki 25790972b22SJoe Perches unsigned long neigh_rand_reach_time(unsigned long base); 2581da177e4SLinus Torvalds 25990972b22SJoe Perches void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, 2601da177e4SLinus Torvalds struct sk_buff *skb); 26190972b22SJoe Perches struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net, 26290972b22SJoe Perches const void *key, struct net_device *dev, 26390972b22SJoe Perches int creat); 26490972b22SJoe Perches struct pneigh_entry *__pneigh_lookup(struct neigh_table *tbl, struct net *net, 26590972b22SJoe Perches const void *key, struct net_device *dev); 26690972b22SJoe Perches int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key, 267fa86d322SPavel Emelyanov struct net_device *dev); 2681da177e4SLinus Torvalds 26990972b22SJoe Perches static inline struct net *pneigh_net(const struct pneigh_entry *pneigh) 27057da52c1SYOSHIFUJI Hideaki { 271e42ea986SEric Dumazet return read_pnet(&pneigh->net); 27257da52c1SYOSHIFUJI Hideaki } 27357da52c1SYOSHIFUJI Hideaki 27490972b22SJoe Perches void neigh_app_ns(struct neighbour *n); 27590972b22SJoe Perches void neigh_for_each(struct neigh_table *tbl, 27690972b22SJoe Perches void (*cb)(struct neighbour *, void *), void *cookie); 27790972b22SJoe Perches void __neigh_for_each_release(struct neigh_table *tbl, 27890972b22SJoe Perches int (*cb)(struct neighbour *)); 27990972b22SJoe Perches void pneigh_for_each(struct neigh_table *tbl, 28090972b22SJoe Perches void (*cb)(struct pneigh_entry *)); 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds struct neigh_seq_state { 28342508461SDenis V. Lunev struct seq_net_private p; 2841da177e4SLinus Torvalds struct neigh_table *tbl; 285d6bf7817SEric Dumazet struct neigh_hash_table *nht; 2861da177e4SLinus Torvalds void *(*neigh_sub_iter)(struct neigh_seq_state *state, 2871da177e4SLinus Torvalds struct neighbour *n, loff_t *pos); 2881da177e4SLinus Torvalds unsigned int bucket; 2891da177e4SLinus Torvalds unsigned int flags; 2901da177e4SLinus Torvalds #define NEIGH_SEQ_NEIGH_ONLY 0x00000001 2911da177e4SLinus Torvalds #define NEIGH_SEQ_IS_PNEIGH 0x00000002 2921da177e4SLinus Torvalds #define NEIGH_SEQ_SKIP_NOARP 0x00000004 2931da177e4SLinus Torvalds }; 29490972b22SJoe Perches void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *, 29590972b22SJoe Perches unsigned int); 29690972b22SJoe Perches void *neigh_seq_next(struct seq_file *, void *, loff_t *); 29790972b22SJoe Perches void neigh_seq_stop(struct seq_file *, void *); 2981da177e4SLinus Torvalds 299cb5b09c1SJiri Pirko int neigh_proc_dointvec(struct ctl_table *ctl, int write, 300cb5b09c1SJiri Pirko void __user *buffer, size_t *lenp, loff_t *ppos); 301cb5b09c1SJiri Pirko int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write, 302cb5b09c1SJiri Pirko void __user *buffer, 303cb5b09c1SJiri Pirko size_t *lenp, loff_t *ppos); 304cb5b09c1SJiri Pirko int neigh_proc_dointvec_ms_jiffies(struct ctl_table *ctl, int write, 305cb5b09c1SJiri Pirko void __user *buffer, 306cb5b09c1SJiri Pirko size_t *lenp, loff_t *ppos); 307cb5b09c1SJiri Pirko 30890972b22SJoe Perches int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p, 30990972b22SJoe Perches char *p_name, proc_handler *proc_handler); 31090972b22SJoe Perches void neigh_sysctl_unregister(struct neigh_parms *p); 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds static inline void __neigh_parms_put(struct neigh_parms *parms) 3131da177e4SLinus Torvalds { 3141da177e4SLinus Torvalds atomic_dec(&parms->refcnt); 3151da177e4SLinus Torvalds } 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms) 3181da177e4SLinus Torvalds { 3191da177e4SLinus Torvalds atomic_inc(&parms->refcnt); 3201da177e4SLinus Torvalds return parms; 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds /* 3241da177e4SLinus Torvalds * Neighbour references 3251da177e4SLinus Torvalds */ 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds static inline void neigh_release(struct neighbour *neigh) 3281da177e4SLinus Torvalds { 3291da177e4SLinus Torvalds if (atomic_dec_and_test(&neigh->refcnt)) 3301da177e4SLinus Torvalds neigh_destroy(neigh); 3311da177e4SLinus Torvalds } 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds static inline struct neighbour * neigh_clone(struct neighbour *neigh) 3341da177e4SLinus Torvalds { 3351da177e4SLinus Torvalds if (neigh) 3361da177e4SLinus Torvalds atomic_inc(&neigh->refcnt); 3371da177e4SLinus Torvalds return neigh; 3381da177e4SLinus Torvalds } 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds #define neigh_hold(n) atomic_inc(&(n)->refcnt) 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb) 3431da177e4SLinus Torvalds { 344ef22b7b6STetsuo Handa unsigned long now = jiffies; 3450ed8ddf4SEric Dumazet 3460ed8ddf4SEric Dumazet if (neigh->used != now) 3470ed8ddf4SEric Dumazet neigh->used = now; 3481da177e4SLinus Torvalds if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE))) 3491da177e4SLinus Torvalds return __neigh_event_send(neigh, skb); 3501da177e4SLinus Torvalds return 0; 3511da177e4SLinus Torvalds } 3521da177e4SLinus Torvalds 353e179e632SBart De Schuymer #ifdef CONFIG_BRIDGE_NETFILTER 354e179e632SBart De Schuymer static inline int neigh_hh_bridge(struct hh_cache *hh, struct sk_buff *skb) 355e179e632SBart De Schuymer { 35695c96174SEric Dumazet unsigned int seq, hh_alen; 357e179e632SBart De Schuymer 358e179e632SBart De Schuymer do { 359e179e632SBart De Schuymer seq = read_seqbegin(&hh->hh_lock); 360e179e632SBart De Schuymer hh_alen = HH_DATA_ALIGN(ETH_HLEN); 361e179e632SBart De Schuymer memcpy(skb->data - hh_alen, hh->hh_data, ETH_ALEN + hh_alen - ETH_HLEN); 362e179e632SBart De Schuymer } while (read_seqretry(&hh->hh_lock, seq)); 363e179e632SBart De Schuymer return 0; 364e179e632SBart De Schuymer } 365e179e632SBart De Schuymer #endif 366e179e632SBart De Schuymer 367425f09abSEric Dumazet static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb) 3683644f0ceSStephen Hemminger { 36995c96174SEric Dumazet unsigned int seq; 3703644f0ceSStephen Hemminger int hh_len; 3713644f0ceSStephen Hemminger 3723644f0ceSStephen Hemminger do { 3733644f0ceSStephen Hemminger seq = read_seqbegin(&hh->hh_lock); 3743644f0ceSStephen Hemminger hh_len = hh->hh_len; 375425f09abSEric Dumazet if (likely(hh_len <= HH_DATA_MOD)) { 376425f09abSEric Dumazet /* this is inlined by gcc */ 377425f09abSEric Dumazet memcpy(skb->data - HH_DATA_MOD, hh->hh_data, HH_DATA_MOD); 378425f09abSEric Dumazet } else { 379425f09abSEric Dumazet int hh_alen = HH_DATA_ALIGN(hh_len); 380425f09abSEric Dumazet 3813644f0ceSStephen Hemminger memcpy(skb->data - hh_alen, hh->hh_data, hh_alen); 382425f09abSEric Dumazet } 3833644f0ceSStephen Hemminger } while (read_seqretry(&hh->hh_lock, seq)); 3843644f0ceSStephen Hemminger 3853644f0ceSStephen Hemminger skb_push(skb, hh_len); 386b23b5455SDavid S. Miller return dev_queue_xmit(skb); 3873644f0ceSStephen Hemminger } 3883644f0ceSStephen Hemminger 3891da177e4SLinus Torvalds static inline struct neighbour * 3901da177e4SLinus Torvalds __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat) 3911da177e4SLinus Torvalds { 3921da177e4SLinus Torvalds struct neighbour *n = neigh_lookup(tbl, pkey, dev); 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds if (n || !creat) 3951da177e4SLinus Torvalds return n; 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds n = neigh_create(tbl, pkey, dev); 3981da177e4SLinus Torvalds return IS_ERR(n) ? NULL : n; 3991da177e4SLinus Torvalds } 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds static inline struct neighbour * 4021da177e4SLinus Torvalds __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey, 4031da177e4SLinus Torvalds struct net_device *dev) 4041da177e4SLinus Torvalds { 4051da177e4SLinus Torvalds struct neighbour *n = neigh_lookup(tbl, pkey, dev); 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds if (n) 4081da177e4SLinus Torvalds return n; 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds return neigh_create(tbl, pkey, dev); 4111da177e4SLinus Torvalds } 4121da177e4SLinus Torvalds 413a61bbcf2SPatrick McHardy struct neighbour_cb { 414a61bbcf2SPatrick McHardy unsigned long sched_next; 415a61bbcf2SPatrick McHardy unsigned int flags; 416a61bbcf2SPatrick McHardy }; 417a61bbcf2SPatrick McHardy 418a61bbcf2SPatrick McHardy #define LOCALLY_ENQUEUED 0x1 419a61bbcf2SPatrick McHardy 420a61bbcf2SPatrick McHardy #define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb) 4211da177e4SLinus Torvalds 4220ed8ddf4SEric Dumazet static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n, 4230ed8ddf4SEric Dumazet const struct net_device *dev) 4240ed8ddf4SEric Dumazet { 4250ed8ddf4SEric Dumazet unsigned int seq; 4260ed8ddf4SEric Dumazet 4270ed8ddf4SEric Dumazet do { 4280ed8ddf4SEric Dumazet seq = read_seqbegin(&n->ha_lock); 4290ed8ddf4SEric Dumazet memcpy(dst, n->ha, dev->addr_len); 4300ed8ddf4SEric Dumazet } while (read_seqretry(&n->ha_lock, seq)); 4310ed8ddf4SEric Dumazet } 4321da177e4SLinus Torvalds #endif 433