2008-12-15 06:53:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2008 Qing Li. All rights reserved.
|
|
|
|
* Copyright (c) 2008 Kip Macy. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#ifndef _NET_IF_LLATBL_H_
|
|
|
|
#define _NET_IF_LLATBL_H_
|
|
|
|
|
|
|
|
#include <sys/_rwlock.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
struct ifnet;
|
|
|
|
struct sysctl_req;
|
|
|
|
struct rt_msghdr;
|
|
|
|
struct rt_addrinfo;
|
|
|
|
|
|
|
|
struct llentry;
|
|
|
|
LIST_HEAD(llentries, llentry);
|
|
|
|
|
2013-05-06 16:42:18 +00:00
|
|
|
extern struct rwlock lltable_rwlock;
|
2009-08-25 09:52:38 +00:00
|
|
|
#define LLTABLE_RLOCK() rw_rlock(&lltable_rwlock)
|
|
|
|
#define LLTABLE_RUNLOCK() rw_runlock(&lltable_rwlock)
|
|
|
|
#define LLTABLE_WLOCK() rw_wlock(&lltable_rwlock)
|
|
|
|
#define LLTABLE_WUNLOCK() rw_wunlock(&lltable_rwlock)
|
|
|
|
#define LLTABLE_LOCK_ASSERT() rw_assert(&lltable_rwlock, RA_LOCKED)
|
|
|
|
|
2008-12-15 06:53:09 +00:00
|
|
|
/*
|
|
|
|
* Code referencing llentry must at least hold
|
|
|
|
* a shared lock
|
|
|
|
*/
|
|
|
|
struct llentry {
|
|
|
|
LIST_ENTRY(llentry) lle_next;
|
2015-08-11 09:26:11 +00:00
|
|
|
union {
|
|
|
|
struct in_addr addr4;
|
|
|
|
struct in6_addr addr6;
|
|
|
|
} r_l3addr;
|
|
|
|
union {
|
|
|
|
uint64_t mac_aligned;
|
|
|
|
uint16_t mac16[3];
|
|
|
|
uint8_t mac8[20]; /* IB needs 20 bytes. */
|
|
|
|
} ll_addr;
|
|
|
|
uint32_t spare0;
|
|
|
|
uint64_t spare1;
|
|
|
|
|
2008-12-15 06:53:09 +00:00
|
|
|
struct lltable *lle_tbl;
|
|
|
|
struct llentries *lle_head;
|
2015-08-10 12:03:59 +00:00
|
|
|
void (*lle_free)(struct llentry *);
|
2008-12-15 06:53:09 +00:00
|
|
|
struct mbuf *la_hold;
|
2012-07-31 11:31:12 +00:00
|
|
|
int la_numheld; /* # of packets currently held */
|
2008-12-15 06:53:09 +00:00
|
|
|
time_t la_expire;
|
2012-07-31 11:31:12 +00:00
|
|
|
uint16_t la_flags;
|
2008-12-15 06:53:09 +00:00
|
|
|
uint16_t la_asked;
|
|
|
|
uint16_t la_preempt;
|
|
|
|
uint16_t ln_byhint;
|
|
|
|
int16_t ln_state; /* IPv6 has ND6_LLINFO_NOSTATE == -2 */
|
2012-07-31 11:31:12 +00:00
|
|
|
uint16_t ln_router;
|
2008-12-15 06:53:09 +00:00
|
|
|
time_t ln_ntick;
|
|
|
|
int lle_refcnt;
|
2012-07-31 11:31:12 +00:00
|
|
|
|
2015-08-10 12:03:59 +00:00
|
|
|
LIST_ENTRY(llentry) lle_chain; /* chain of deleted items */
|
2015-08-11 12:38:54 +00:00
|
|
|
struct callout lle_timer;
|
2015-08-11 09:26:11 +00:00
|
|
|
struct rwlock lle_lock;
|
2008-12-15 06:53:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define LLE_WLOCK(lle) rw_wlock(&(lle)->lle_lock)
|
|
|
|
#define LLE_RLOCK(lle) rw_rlock(&(lle)->lle_lock)
|
|
|
|
#define LLE_WUNLOCK(lle) rw_wunlock(&(lle)->lle_lock)
|
|
|
|
#define LLE_RUNLOCK(lle) rw_runlock(&(lle)->lle_lock)
|
|
|
|
#define LLE_DOWNGRADE(lle) rw_downgrade(&(lle)->lle_lock)
|
|
|
|
#define LLE_TRY_UPGRADE(lle) rw_try_upgrade(&(lle)->lle_lock)
|
|
|
|
#define LLE_LOCK_INIT(lle) rw_init_flags(&(lle)->lle_lock, "lle", RW_DUPOK)
|
2008-12-16 00:20:15 +00:00
|
|
|
#define LLE_LOCK_DESTROY(lle) rw_destroy(&(lle)->lle_lock)
|
2008-12-15 06:53:09 +00:00
|
|
|
#define LLE_WLOCK_ASSERT(lle) rw_assert(&(lle)->lle_lock, RA_WLOCKED)
|
|
|
|
|
|
|
|
#define LLE_IS_VALID(lle) (((lle) != NULL) && ((lle) != (void *)-1))
|
|
|
|
|
|
|
|
#define LLE_ADDREF(lle) do { \
|
|
|
|
LLE_WLOCK_ASSERT(lle); \
|
|
|
|
KASSERT((lle)->lle_refcnt >= 0, \
|
2012-08-02 13:57:49 +00:00
|
|
|
("negative refcnt %d on lle %p", \
|
|
|
|
(lle)->lle_refcnt, (lle))); \
|
2008-12-15 06:53:09 +00:00
|
|
|
(lle)->lle_refcnt++; \
|
|
|
|
} while (0)
|
2012-07-31 11:31:12 +00:00
|
|
|
|
2008-12-15 06:53:09 +00:00
|
|
|
#define LLE_REMREF(lle) do { \
|
|
|
|
LLE_WLOCK_ASSERT(lle); \
|
2012-08-02 13:57:49 +00:00
|
|
|
KASSERT((lle)->lle_refcnt > 0, \
|
|
|
|
("bogus refcnt %d on lle %p", \
|
|
|
|
(lle)->lle_refcnt, (lle))); \
|
2008-12-15 06:53:09 +00:00
|
|
|
(lle)->lle_refcnt--; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define LLE_FREE_LOCKED(lle) do { \
|
2012-08-02 13:57:49 +00:00
|
|
|
if ((lle)->lle_refcnt == 1) \
|
2015-08-10 12:03:59 +00:00
|
|
|
(lle)->lle_free(lle); \
|
2008-12-15 06:53:09 +00:00
|
|
|
else { \
|
2012-08-02 13:57:49 +00:00
|
|
|
LLE_REMREF(lle); \
|
2008-12-15 06:53:09 +00:00
|
|
|
LLE_WUNLOCK(lle); \
|
|
|
|
} \
|
|
|
|
/* guard against invalid refs */ \
|
2012-08-02 13:57:49 +00:00
|
|
|
(lle) = NULL; \
|
2008-12-15 06:53:09 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define LLE_FREE(lle) do { \
|
|
|
|
LLE_WLOCK(lle); \
|
2010-12-31 21:57:54 +00:00
|
|
|
LLE_FREE_LOCKED(lle); \
|
2008-12-15 06:53:09 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2014-11-15 18:54:07 +00:00
|
|
|
typedef struct llentry *(llt_lookup_t)(struct lltable *, u_int flags,
|
|
|
|
const struct sockaddr *l3addr);
|
2015-08-20 12:05:17 +00:00
|
|
|
typedef struct llentry *(llt_alloc_t)(struct lltable *, u_int flags,
|
2014-11-15 18:54:07 +00:00
|
|
|
const struct sockaddr *l3addr);
|
2015-09-14 16:48:19 +00:00
|
|
|
typedef void (llt_delete_t)(struct lltable *, struct llentry *);
|
2014-11-15 18:54:07 +00:00
|
|
|
typedef void (llt_prefix_free_t)(struct lltable *,
|
2015-09-14 16:48:19 +00:00
|
|
|
const struct sockaddr *addr, const struct sockaddr *mask, u_int flags);
|
2015-08-10 12:03:59 +00:00
|
|
|
typedef int (llt_dump_entry_t)(struct lltable *, struct llentry *,
|
|
|
|
struct sysctl_req *);
|
|
|
|
typedef uint32_t (llt_hash_t)(const struct llentry *, uint32_t);
|
|
|
|
typedef int (llt_match_prefix_t)(const struct sockaddr *,
|
|
|
|
const struct sockaddr *, u_int, struct llentry *);
|
|
|
|
typedef void (llt_free_entry_t)(struct lltable *, struct llentry *);
|
|
|
|
typedef void (llt_fill_sa_entry_t)(const struct llentry *, struct sockaddr *);
|
2015-08-11 05:51:00 +00:00
|
|
|
typedef void (llt_free_tbl_t)(struct lltable *);
|
2015-08-10 12:03:59 +00:00
|
|
|
typedef void (llt_link_entry_t)(struct lltable *, struct llentry *);
|
|
|
|
typedef void (llt_unlink_entry_t)(struct llentry *);
|
|
|
|
|
|
|
|
typedef int (llt_foreach_cb_t)(struct lltable *, struct llentry *, void *);
|
|
|
|
typedef int (llt_foreach_entry_t)(struct lltable *, llt_foreach_cb_t *, void *);
|
2014-11-15 18:54:07 +00:00
|
|
|
|
2008-12-15 06:53:09 +00:00
|
|
|
struct lltable {
|
|
|
|
SLIST_ENTRY(lltable) llt_link;
|
|
|
|
int llt_af;
|
2015-08-11 05:51:00 +00:00
|
|
|
int llt_hsize;
|
|
|
|
struct llentries *lle_head;
|
2008-12-15 06:53:09 +00:00
|
|
|
struct ifnet *llt_ifp;
|
|
|
|
|
2014-11-15 18:54:07 +00:00
|
|
|
llt_lookup_t *llt_lookup;
|
2015-08-20 12:05:17 +00:00
|
|
|
llt_alloc_t *llt_alloc_entry;
|
2015-09-14 16:48:19 +00:00
|
|
|
llt_delete_t *llt_delete_entry;
|
2014-11-15 18:54:07 +00:00
|
|
|
llt_prefix_free_t *llt_prefix_free;
|
2015-08-10 12:03:59 +00:00
|
|
|
llt_dump_entry_t *llt_dump_entry;
|
|
|
|
llt_hash_t *llt_hash;
|
|
|
|
llt_match_prefix_t *llt_match_prefix;
|
|
|
|
llt_free_entry_t *llt_free_entry;
|
|
|
|
llt_foreach_entry_t *llt_foreach_entry;
|
|
|
|
llt_link_entry_t *llt_link_entry;
|
|
|
|
llt_unlink_entry_t *llt_unlink_entry;
|
|
|
|
llt_fill_sa_entry_t *llt_fill_sa_entry;
|
2015-08-11 05:51:00 +00:00
|
|
|
llt_free_tbl_t *llt_free_tbl;
|
2008-12-15 06:53:09 +00:00
|
|
|
};
|
2014-11-15 18:54:07 +00:00
|
|
|
|
2008-12-15 06:53:09 +00:00
|
|
|
MALLOC_DECLARE(M_LLTABLE);
|
|
|
|
|
|
|
|
/*
|
2015-08-08 17:48:54 +00:00
|
|
|
* LLentry flags
|
2008-12-15 06:53:09 +00:00
|
|
|
*/
|
|
|
|
#define LLE_DELETED 0x0001 /* entry must be deleted */
|
|
|
|
#define LLE_STATIC 0x0002 /* entry is static */
|
|
|
|
#define LLE_IFADDR 0x0004 /* entry is interface addr */
|
|
|
|
#define LLE_VALID 0x0008 /* ll_addr is valid */
|
Fix the handling of IPv6 On-Link Redirects.
On receipt of a redirect message, install an interface route for the
redirected destination. On removal of the corresponding Neighbor Cache
entry, remove the interface route.
This requires changes in rtredirect_fib() to cope with an AF_LINK
address for the gateway and with the absence of RTF_GATEWAY.
This fixes the "Redirected On-Link" test cases in the Tahi IPv6 Ready Logo
Phase 2 test suite.
Unrelated to the above, fix a recursion on the radix node head lock
triggered by the Tahi Redirected to Alternate Router test cases.
When I first wrote this patch in October 2012, all Section 2
(Neighbor Discovery) test cases passed on 10-CURRENT, 9-STABLE,
and 8-STABLE. cem@ recently rebased the 10.x patch onto head and reported
that it passes Tahi. (Thanks!)
These other test cases also passed in 2012:
* the RTF_MODIFIED case, with IPv4 and IPv6 (using a
RTF_HOST|RTF_GATEWAY route for the destination)
* the redirected-to-self case, with IPv4 and IPv6
* a valid IPv4 redirect
All testing in 2012 was done with WITNESS and INVARIANTS.
Tested by: EMC / Isilon Storage Division via Conrad Meyer (cem) in 2015,
Mark Kelley <mark_kelley@dell.com> in 2012,
TC Telkamp <terence_telkamp@dell.com> in 2012
PR: 152791
Reviewed by: melifaro (current rev), bz (earlier rev)
Approved by: kib (mentor)
MFC after: 1 month
Relnotes: yes
Sponsored by: Dell Inc.
Differential Revision: https://reviews.freebsd.org/D3602
2015-09-14 19:17:25 +00:00
|
|
|
#define LLE_REDIRECT 0x0010 /* installed by redirect; has host rtentry */
|
2008-12-15 06:53:09 +00:00
|
|
|
#define LLE_PUB 0x0020 /* publish entry ??? */
|
2012-08-02 13:57:49 +00:00
|
|
|
#define LLE_LINKED 0x0040 /* linked to lookup structure */
|
2014-11-15 18:54:07 +00:00
|
|
|
/* LLE request flags */
|
2012-07-31 11:31:12 +00:00
|
|
|
#define LLE_EXCLUSIVE 0x2000 /* return lle xlocked */
|
2008-12-15 06:53:09 +00:00
|
|
|
|
|
|
|
#define LLATBL_HASH(key, mask) \
|
|
|
|
(((((((key >> 8) ^ key) >> 8) ^ key) >> 8) ^ key) & mask)
|
|
|
|
|
2015-08-11 05:51:00 +00:00
|
|
|
struct lltable *lltable_allocate_htbl(uint32_t hsize);
|
2008-12-15 06:53:09 +00:00
|
|
|
void lltable_free(struct lltable *);
|
2015-08-11 05:51:00 +00:00
|
|
|
void lltable_link(struct lltable *llt);
|
2012-07-31 11:31:12 +00:00
|
|
|
void lltable_prefix_free(int, struct sockaddr *,
|
|
|
|
struct sockaddr *, u_int);
|
2010-10-16 18:42:09 +00:00
|
|
|
#if 0
|
2008-12-15 06:53:09 +00:00
|
|
|
void lltable_drain(int);
|
2010-10-16 18:42:09 +00:00
|
|
|
#endif
|
2008-12-15 06:53:09 +00:00
|
|
|
int lltable_sysctl_dumparp(int, struct sysctl_req *);
|
|
|
|
|
2010-11-12 22:03:02 +00:00
|
|
|
size_t llentry_free(struct llentry *);
|
2012-08-02 13:20:44 +00:00
|
|
|
struct llentry *llentry_alloc(struct ifnet *, struct lltable *,
|
|
|
|
struct sockaddr_storage *);
|
2008-12-15 06:53:09 +00:00
|
|
|
|
2015-08-10 12:03:59 +00:00
|
|
|
/* helper functions */
|
|
|
|
size_t lltable_drop_entry_queue(struct llentry *);
|
|
|
|
|
2015-08-20 12:05:17 +00:00
|
|
|
struct llentry *lltable_alloc_entry(struct lltable *llt, u_int flags,
|
|
|
|
const struct sockaddr *l4addr);
|
|
|
|
void lltable_free_entry(struct lltable *llt, struct llentry *lle);
|
2015-09-14 16:48:19 +00:00
|
|
|
int lltable_delete_addr(struct lltable *llt, u_int flags,
|
|
|
|
const struct sockaddr *l3addr);
|
2015-08-10 12:03:59 +00:00
|
|
|
void lltable_link_entry(struct lltable *llt, struct llentry *lle);
|
|
|
|
void lltable_unlink_entry(struct lltable *llt, struct llentry *lle);
|
|
|
|
void lltable_fill_sa_entry(const struct llentry *lle, struct sockaddr *sa);
|
|
|
|
struct ifnet *lltable_get_ifp(const struct lltable *llt);
|
|
|
|
int lltable_get_af(const struct lltable *llt);
|
|
|
|
|
|
|
|
int lltable_foreach_lle(struct lltable *llt, llt_foreach_cb_t *f,
|
|
|
|
void *farg);
|
2008-12-15 06:53:09 +00:00
|
|
|
/*
|
|
|
|
* Generic link layer address lookup function.
|
|
|
|
*/
|
|
|
|
static __inline struct llentry *
|
|
|
|
lla_lookup(struct lltable *llt, u_int flags, const struct sockaddr *l3addr)
|
|
|
|
{
|
2014-11-15 18:54:07 +00:00
|
|
|
|
2015-08-08 17:48:54 +00:00
|
|
|
return (llt->llt_lookup(llt, flags, l3addr));
|
2008-12-15 06:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int lla_rt_output(struct rt_msghdr *, struct rt_addrinfo *);
|
2013-01-25 23:58:21 +00:00
|
|
|
|
|
|
|
#include <sys/eventhandler.h>
|
|
|
|
enum {
|
|
|
|
LLENTRY_RESOLVED,
|
|
|
|
LLENTRY_TIMEDOUT,
|
|
|
|
LLENTRY_DELETED,
|
|
|
|
LLENTRY_EXPIRED,
|
|
|
|
};
|
|
|
|
typedef void (*lle_event_fn)(void *, struct llentry *, int);
|
|
|
|
EVENTHANDLER_DECLARE(lle_event, lle_event_fn);
|
2008-12-15 06:53:09 +00:00
|
|
|
#endif /* _NET_IF_LLATBL_H_ */
|