svn commit: r276624 - in projects/routing/sys: net netinet netinet6

Alexander V. Chernikov melifaro at FreeBSD.org
Sat Jan 3 16:04:32 UTC 2015


Author: melifaro
Date: Sat Jan  3 16:04:28 2015
New Revision: 276624
URL: https://svnweb.freebsd.org/changeset/base/276624

Log:
  * Hide lltable implementation details in if_llatbl_var.h
  * Make most of lltable_* methods 'normal' functions instead of inline
  * Add lltable_get_<af|ifp>() functions to access given lltable fields
  * Temporarily resurrect nd6_lookup() function

Added:
  projects/routing/sys/net/if_llatbl_var.h   (contents, props changed)
Modified:
  projects/routing/sys/net/if_llatbl.c
  projects/routing/sys/net/if_llatbl.h
  projects/routing/sys/net/rt_nhops.c
  projects/routing/sys/netinet/if_ether.c
  projects/routing/sys/netinet/in.c
  projects/routing/sys/netinet/toecore.c
  projects/routing/sys/netinet6/in6.c
  projects/routing/sys/netinet6/nd6.c
  projects/routing/sys/netinet6/nd6.h

Modified: projects/routing/sys/net/if_llatbl.c
==============================================================================
--- projects/routing/sys/net/if_llatbl.c	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/net/if_llatbl.c	Sat Jan  3 16:04:28 2015	(r276624)
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
 
 #include <netinet/in.h>
 #include <net/if_llatbl.h>
+#include <net/if_llatbl_var.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <net/if_var.h>
@@ -433,6 +434,64 @@ lltable_unlink(struct lltable *llt)
 }
 
 /*
+ * External methods used by lltable consumers
+ */
+
+struct llentry *
+lltable_create_lle(struct lltable *llt, u_int flags,
+    const void *paddr)
+{
+
+	return (llt->llt_create(llt, flags, paddr));
+}
+
+int
+lltable_delete_addr(struct lltable *llt, u_int flags,
+    const struct sockaddr *l3addr)
+{
+
+	return llt->llt_delete_addr(llt, flags, l3addr);
+}
+
+void
+lltable_link_entry(struct lltable *llt, struct llentry *lle)
+{
+
+	llt->llt_link_entry(llt, lle);
+}
+
+void
+lltable_unlink_entry(struct lltable *llt, struct llentry *lle)
+{
+
+	llt->llt_unlink_entry(lle);
+}
+
+void
+lltable_fill_sa_entry(const struct llentry *lle, struct sockaddr *sa)
+{
+	struct lltable *llt;
+
+	llt = lle->lle_tbl;
+
+	llt->llt_fill_sa_entry(lle, sa);
+}
+
+struct ifnet *
+lltable_get_ifp(const struct lltable *llt)
+{
+
+	return (llt->llt_ifp);
+}
+
+int
+lltable_get_af(const struct lltable *llt)
+{
+
+	return (llt->llt_af);
+}
+
+/*
  * Called in route_output when rtm_flags contains RTF_LLDATA.
  */
 int

Modified: projects/routing/sys/net/if_llatbl.h
==============================================================================
--- projects/routing/sys/net/if_llatbl.h	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/net/if_llatbl.h	Sat Jan  3 16:04:28 2015	(r276624)
@@ -24,7 +24,6 @@
  * 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_
@@ -34,20 +33,9 @@ __FBSDID("$FreeBSD$");
 #include <netinet/in.h>
 
 struct ifnet;
-struct sysctl_req;
-struct rt_msghdr;
-struct rt_addrinfo;
-
 struct llentry;
 LIST_HEAD(llentries, llentry);
 
-extern struct rwlock lltable_rwlock;
-#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)
-
 struct llentry {
 	/* FIELDS PROTECTED BY IFDATA LOCK */
 	LIST_ENTRY(llentry)	 lle_next;
@@ -88,7 +76,6 @@ struct llentry {
 		struct callout	ln_timer_ch;
 		struct callout  la_timer;
 	} lle_timer;
-	/* NB: struct sockaddr must immediately follow */
 };
 
 #define	LLE_WLOCK(lle)		rw_wlock(&(lle)->lle_lock)
@@ -135,62 +122,6 @@ struct llentry {
 #define	ln_timer_ch	lle_timer.ln_timer_ch
 #define	la_timer	lle_timer.la_timer
 
-#ifndef LLTBL_HASHTBL_SIZE
-#define	LLTBL_HASHTBL_SIZE	32	/* default 32 ? */
-#endif
-
-#ifndef LLTBL_HASHMASK
-#define	LLTBL_HASHMASK	(LLTBL_HASHTBL_SIZE - 1)
-#endif
-
-typedef	struct llentry *(llt_lookup_t)(struct lltable *, u_int flags,
-    const void *paddr);
-typedef	struct llentry *(llt_create_t)(struct lltable *, u_int flags,
-    const void *paddr);
-typedef	int (llt_delete_addr_t)(struct lltable *, u_int flags,
-    const struct sockaddr *l3addr);
-typedef int (llt_dump_entry_t)(struct lltable *, struct llentry *,
-    struct sysctl_req *);
-typedef uint32_t (llt_hash_t)(const struct llentry *);
-typedef int (llt_match_prefix_t)(const struct sockaddr *,
-    const struct sockaddr *, u_int, struct llentry *);
-typedef void (llt_clear_entry_t)(struct lltable *, struct llentry *);
-typedef void (llt_free_tbl_t)(struct lltable *);
-typedef void (llt_link_entry_t)(struct lltable *, struct llentry *);
-typedef void (llt_unlink_entry_t)(struct llentry *);
-typedef int (llt_prepare_sentry_t)(struct lltable *, struct llentry *,
-    struct rt_addrinfo *);
-typedef const void *(llt_get_sa_addr_t)(const struct sockaddr *l3addr);
-typedef void (llt_fill_sa_entry_t)(const struct llentry *, struct sockaddr *);
-
-typedef int (llt_foreach_cb_t)(struct lltable *, struct llentry *, void *);
-typedef int (llt_foreach_entry_t)(struct lltable *, llt_foreach_cb_t *, void *);
-
-
-struct lltable {
-	SLIST_ENTRY(lltable)	llt_link;
-	struct llentries	lle_head[LLTBL_HASHTBL_SIZE];
-	int			llt_af;
-	struct ifnet		*llt_ifp;
-
-	llt_lookup_t		*llt_lookup;
-	llt_create_t		*llt_create;
-	llt_delete_addr_t	*llt_delete_addr;
-	llt_dump_entry_t	*llt_dump_entry;
-	llt_hash_t		*llt_hash;
-	llt_match_prefix_t	*llt_match_prefix;
-	llt_clear_entry_t	*llt_clear_entry;
-	llt_foreach_entry_t	*llt_foreach_entry;
-	llt_link_entry_t	*llt_link_entry;
-	llt_unlink_entry_t	*llt_unlink_entry;
-	llt_prepare_sentry_t	*llt_prepare_static_entry;
-	llt_get_sa_addr_t	*llt_get_sa_addr;
-	llt_fill_sa_entry_t	*llt_fill_sa_entry;
-	llt_free_tbl_t		*llt_free_tbl;
-};
-
-MALLOC_DECLARE(M_LLTABLE);
-
 /*
  * LLE flags used by fast path code
  */
@@ -210,77 +141,6 @@ MALLOC_DECLARE(M_LLTABLE);
 #define	LLE_UNLOCKED	0x0100	/* return lle unlocked  */
 #define	LLE_EXCLUSIVE	0x0200	/* return lle wlocked  */
 
-#define LLATBL_HASH(key, mask) \
-	(((((((key >> 8) ^ key) >> 8) ^ key) >> 8) ^ key) & mask)
-
-void		lltable_link(struct lltable *);
-void		lltable_free(struct lltable *);
-void		lltable_prefix_free(int, struct sockaddr *,
-		    struct sockaddr *, u_int);
-#if 0
-void		lltable_drain(int);
-#endif
-int		lltable_sysctl_dumparp(int, struct sysctl_req *);
-
-struct llentry  *llentry_alloc(struct ifnet *, struct lltable *,
-		    struct sockaddr_storage *);
-
-/* helper functions */
-size_t		lltable_drop_entry_queue(struct llentry *);
-
-/*
- * Generic link layer address lookup function.
- */
-static __inline struct llentry *
-lltable_lookup_lle(struct lltable *llt, u_int flags,
-    const void *paddr)
-{
-
-	return (llt->llt_lookup(llt, flags, paddr));
-}
-
-static __inline struct llentry *
-lltable_create_lle(struct lltable *llt, u_int flags,
-    const void *paddr)
-{
-
-	return (llt->llt_create(llt, flags, paddr));
-}
-
-static __inline int
-lltable_delete_addr(struct lltable *llt, u_int flags,
-    const struct sockaddr *l3addr)
-{
-
-	return llt->llt_delete_addr(llt, flags, l3addr);
-}
-
-static __inline void
-lltable_link_entry(struct lltable *llt, struct llentry *lle)
-{
-
-	llt->llt_link_entry(llt, lle);
-}
-
-static __inline void
-lltable_unlink_entry(struct lltable *llt, struct llentry *lle)
-{
-
-	llt->llt_unlink_entry(lle);
-}
-
-static __inline void
-lltable_fill_sa_entry(const struct llentry *lle, struct sockaddr *sa)
-{
-	struct lltable *llt;
-
-	llt = lle->lle_tbl;
-
-	llt->llt_fill_sa_entry(lle, sa);
-}
-
-int		lla_rt_output(struct rt_msghdr *, struct rt_addrinfo *);
-
 #include <sys/eventhandler.h>
 enum {
 	LLENTRY_RESOLVED,
@@ -290,4 +150,21 @@ enum {
 };
 typedef void (*lle_event_fn)(void *, struct llentry *, int);
 EVENTHANDLER_DECLARE(lle_event, lle_event_fn);
+
+struct sysctl_req;
+struct rt_msghdr;
+struct rt_addrinfo;
+int lltable_sysctl_dumparp(int af, struct sysctl_req *wr);
+int lla_rt_output(struct rt_msghdr *, struct rt_addrinfo *);
+
+void lltable_fill_sa_entry(const struct llentry *lle, struct sockaddr *sa);
+void lltable_prefix_free(int af, struct sockaddr *prefix, struct sockaddr *mask,
+    u_int flags);
+struct ifnet *lltable_get_ifp(const struct lltable *llt);
+int lltable_get_af(const struct lltable *llt);
+
+/* XXX: Remove after converting flowtable */
+struct llentry *llentry_alloc(struct ifnet *ifp, struct lltable *lt,
+    struct sockaddr_storage *dst);
+
 #endif  /* _NET_IF_LLATBL_H_ */

Added: projects/routing/sys/net/if_llatbl_var.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/routing/sys/net/if_llatbl_var.h	Sat Jan  3 16:04:28 2015	(r276624)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2014 Alexander V. Chernikov. 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.
+ */
+__FBSDID("$FreeBSD$");
+
+#ifndef	_NET_IF_LLATBL_VAR_H_
+#define	_NET_IF_LLATBL_VAR_H_
+
+
+extern struct rwlock lltable_rwlock;
+#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)
+
+#ifndef LLTBL_HASHTBL_SIZE
+#define	LLTBL_HASHTBL_SIZE	32	/* default 32 ? */
+#endif
+
+#ifndef LLTBL_HASHMASK
+#define	LLTBL_HASHMASK	(LLTBL_HASHTBL_SIZE - 1)
+#endif
+
+#define LLATBL_HASH(key, mask) \
+	(((((((key >> 8) ^ key) >> 8) ^ key) >> 8) ^ key) & mask)
+
+typedef	struct llentry *(llt_lookup_t)(struct lltable *, u_int flags,
+    const void *paddr);
+typedef	struct llentry *(llt_create_t)(struct lltable *, u_int flags,
+    const void *paddr);
+typedef	int (llt_delete_addr_t)(struct lltable *, u_int flags,
+    const struct sockaddr *l3addr);
+typedef int (llt_dump_entry_t)(struct lltable *, struct llentry *,
+    struct sysctl_req *);
+typedef uint32_t (llt_hash_t)(const struct llentry *);
+typedef int (llt_match_prefix_t)(const struct sockaddr *,
+    const struct sockaddr *, u_int, struct llentry *);
+typedef void (llt_clear_entry_t)(struct lltable *, struct llentry *);
+typedef void (llt_free_tbl_t)(struct lltable *);
+typedef void (llt_link_entry_t)(struct lltable *, struct llentry *);
+typedef void (llt_unlink_entry_t)(struct llentry *);
+typedef int (llt_prepare_sentry_t)(struct lltable *, struct llentry *,
+    struct rt_addrinfo *);
+typedef const void *(llt_get_sa_addr_t)(const struct sockaddr *l3addr);
+typedef void (llt_fill_sa_entry_t)(const struct llentry *, struct sockaddr *);
+
+typedef int (llt_foreach_cb_t)(struct lltable *, struct llentry *, void *);
+typedef int (llt_foreach_entry_t)(struct lltable *, llt_foreach_cb_t *, void *);
+
+
+struct lltable {
+	SLIST_ENTRY(lltable)	llt_link;
+	struct llentries	lle_head[LLTBL_HASHTBL_SIZE];
+	int			llt_af;
+	struct ifnet		*llt_ifp;
+
+	llt_lookup_t		*llt_lookup;
+	llt_create_t		*llt_create;
+	llt_delete_addr_t	*llt_delete_addr;
+	llt_dump_entry_t	*llt_dump_entry;
+	llt_hash_t		*llt_hash;
+	llt_match_prefix_t	*llt_match_prefix;
+	llt_clear_entry_t	*llt_clear_entry;
+	llt_foreach_entry_t	*llt_foreach_entry;
+	llt_link_entry_t	*llt_link_entry;
+	llt_unlink_entry_t	*llt_unlink_entry;
+	llt_prepare_sentry_t	*llt_prepare_static_entry;
+	llt_get_sa_addr_t	*llt_get_sa_addr;
+	llt_fill_sa_entry_t	*llt_fill_sa_entry;
+	llt_free_tbl_t		*llt_free_tbl;
+};
+
+MALLOC_DECLARE(M_LLTABLE);
+
+void lltable_link(struct lltable *llt);
+void lltable_free(struct lltable *llt);
+
+/* helper functions */
+size_t lltable_drop_entry_queue(struct llentry *);
+
+/*
+ * Generic link layer table methods.
+ */
+
+static __inline struct llentry *
+lltable_lookup_lle(struct lltable *llt, u_int flags,
+    const void *paddr)
+{
+
+	return (llt->llt_lookup(llt, flags, paddr));
+}
+
+struct llentry *lltable_create_lle(struct lltable *llt, u_int flags,
+    const void *paddr);
+int lltable_delete_addr(struct lltable *llt, u_int flags,
+    const struct sockaddr *l3addr);
+void lltable_link_entry(struct lltable *llt, struct llentry *lle);
+void lltable_unlink_entry(struct lltable *llt, struct llentry *lle);
+
+
+#endif

Modified: projects/routing/sys/net/rt_nhops.c
==============================================================================
--- projects/routing/sys/net/rt_nhops.c	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/net/rt_nhops.c	Sat Jan  3 16:04:28 2015	(r276624)
@@ -74,6 +74,7 @@
 #include <netinet6/scope6_var.h>
 
 #include <net/if_llatbl.h>
+#include <net/if_llatbl_var.h>
 
 #include <net/if_types.h>
 #include <netinet/if_ether.h>

Modified: projects/routing/sys/netinet/if_ether.c
==============================================================================
--- projects/routing/sys/netinet/if_ether.c	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/netinet/if_ether.c	Sat Jan  3 16:04:28 2015	(r276624)
@@ -66,6 +66,7 @@ __FBSDID("$FreeBSD$");
 #include <netinet/in.h>
 #include <netinet/in_var.h>
 #include <net/if_llatbl.h>
+#include <net/if_llatbl_var.h>
 #include <netinet/if_ether.h>
 #ifdef INET
 #include <netinet/ip_carp.h>

Modified: projects/routing/sys/netinet/in.c
==============================================================================
--- projects/routing/sys/netinet/in.c	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/netinet/in.c	Sat Jan  3 16:04:28 2015	(r276624)
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_arp.h>
 #include <net/if_dl.h>
 #include <net/if_llatbl.h>
+#include <net/if_llatbl_var.h>
 #include <net/if_types.h>
 #include <net/route.h>
 #include <net/vnet.h>

Modified: projects/routing/sys/netinet/toecore.c
==============================================================================
--- projects/routing/sys/netinet/toecore.c	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/netinet/toecore.c	Sat Jan  3 16:04:28 2015	(r276624)
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_types.h>
 #include <net/if_vlan_var.h>
 #include <net/if_llatbl.h>
+#include <net/if_llatbl_var.h>
 #include <net/route.h>
 
 #include <netinet/if_ether.h>
@@ -397,8 +398,8 @@ toe_lle_event(void *arg __unused, struct
 
 	LLE_WLOCK_ASSERT(lle);
 
-	ifp = lle->lle_tbl->llt_ifp;
-	sa_family = lle->lle_tbl->llt_af;
+	ifp = lltable_get_ifp(lle->lle_tbl);
+	sa_family = lltable_get_af(lle->lle_tbl);
 
 #if 0
 	/* XXX: Do not panic, ignore event instead */

Modified: projects/routing/sys/netinet6/in6.c
==============================================================================
--- projects/routing/sys/netinet6/in6.c	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/netinet6/in6.c	Sat Jan  3 16:04:28 2015	(r276624)
@@ -95,6 +95,7 @@ __FBSDID("$FreeBSD$");
 #include <netinet/in.h>
 #include <netinet/in_var.h>
 #include <net/if_llatbl.h>
+#include <net/if_llatbl_var.h>
 #include <netinet/if_ether.h>
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>

Modified: projects/routing/sys/netinet6/nd6.c
==============================================================================
--- projects/routing/sys/netinet6/nd6.c	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/netinet6/nd6.c	Sat Jan  3 16:04:28 2015	(r276624)
@@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
 #include <netinet/in.h>
 #include <netinet/in_kdtrace.h>
 #include <net/if_llatbl.h>
+#include <net/if_llatbl_var.h>
 #include <netinet/if_ether.h>
 #include <netinet6/in6_var.h>
 #include <netinet/ip6.h>
@@ -815,6 +816,15 @@ regen_tmpaddr(struct in6_ifaddr *ia6)
 	return (-1);
 }
 
+
+struct llentry *
+nd6_lookup(struct in6_addr *addr, u_int flags, struct ifnet *ifp)
+{
+
+	return (lltable_lookup_lle(LLTABLE6(ifp), flags, addr));
+}
+
+
 /*
  * Nuke neighbor cache/prefix/default router management table, right before
  * ifp goes away.

Modified: projects/routing/sys/netinet6/nd6.h
==============================================================================
--- projects/routing/sys/netinet6/nd6.h	Sat Jan  3 15:39:04 2015	(r276623)
+++ projects/routing/sys/netinet6/nd6.h	Sat Jan  3 16:04:28 2015	(r276624)
@@ -403,7 +403,9 @@ _check_in6_addr_typecast(const struct in
 #define	lltable_create_lle6(i, f, a)	\
 	lltable_create_lle(LLTABLE6(i), (f), _check_in6_addr_typecast(a))
 
-#define	nd6_lookup(a, f, i)	lltable_lookup_lle6((i), (f), (a))
+struct llentry *nd6_lookup(struct in6_addr *addr, u_int flags,
+    struct ifnet *ifp);
+
 #define	ND6_EXCLUSIVE		LLE_EXCLUSIVE
 
 


More information about the svn-src-projects mailing list