summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-07-27 13:34:31 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-07-27 13:34:31 +0000
commitaf08e4239d25c6700d16463c12cb93fb2be43b30 (patch)
tree1f0b3c9179ff94423606d01b23090811ce72d69b
parent9777f7d53dad3a2c15957419d1a9dd5ef5853648 (diff)
Compile and test MPATH code.
-rw-r--r--regress/sys/net/rtable/Makefile.inc4
-rw-r--r--regress/sys/net/rtable/kern_compat.h10
-rw-r--r--regress/sys/net/rtable/srp_compat.h22
-rw-r--r--regress/sys/net/rtable/util.c104
-rw-r--r--regress/sys/net/rtable/util.h5
5 files changed, 138 insertions, 7 deletions
diff --git a/regress/sys/net/rtable/Makefile.inc b/regress/sys/net/rtable/Makefile.inc
index fd4de2fae34..8907346bd3a 100644
--- a/regress/sys/net/rtable/Makefile.inc
+++ b/regress/sys/net/rtable/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.2 2016/09/21 07:13:02 mpi Exp $
+# $OpenBSD: Makefile.inc,v 1.3 2017/07/27 13:34:30 mpi Exp $
TOPDIR= ${.CURDIR}/..
@@ -9,6 +9,6 @@ SRCS+= art.c
CFLAGS+= -DART
.endif
-CPPFLAGS+= -I${TOPDIR} -Wall -DSMALL_KERNEL
+CPPFLAGS+= -I${TOPDIR} -Wall
.PATH: ${TOPDIR} ${TOPDIR}/../../../../sys/net
diff --git a/regress/sys/net/rtable/kern_compat.h b/regress/sys/net/rtable/kern_compat.h
index e1275c38050..a83110de976 100644
--- a/regress/sys/net/rtable/kern_compat.h
+++ b/regress/sys/net/rtable/kern_compat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_compat.h,v 1.6 2017/06/06 13:19:29 mpi Exp $ */
+/* $OpenBSD: kern_compat.h,v 1.7 2017/07/27 13:34:30 mpi Exp $ */
#ifndef _KERN_COMPAT_H_
#define _KERN_COMPAT_H_
@@ -71,4 +71,12 @@ extern struct domain *domains[];
#define rw_exit_write(rwl)
#define rw_assert_wrlock(rwl)
+#define SET(t, f) ((t) |= (f))
+#define CLR(t, f) ((t) &= ~(f))
+#define ISSET(t, f) ((t) & (f))
+
+struct rtentry;
+
+int rt_hash(struct rtentry *, struct sockaddr *, uint32_t *);
+
#endif /* _KERN_COMPAT_H_ */
diff --git a/regress/sys/net/rtable/srp_compat.h b/regress/sys/net/rtable/srp_compat.h
index 3781956e2a3..3059ac0de03 100644
--- a/regress/sys/net/rtable/srp_compat.h
+++ b/regress/sys/net/rtable/srp_compat.h
@@ -9,7 +9,6 @@
* SRP glue.
*/
-#define srp_enter(_sr, _s) ((_s)->ref)
#define srp_follow(_sr, _s) ((_s)->ref)
#define srp_leave(_sr) do { } while (0)
#define srp_swap(_srp, _v) srp_swap_locked((_srp), (_v))
@@ -19,6 +18,12 @@
#define srp_get_locked(_s) ((_s)->ref)
static inline void *
+srp_enter(struct srp_ref *_sr, struct srp *_s)
+{
+ return (_s->ref);
+}
+
+static inline void *
srp_swap_locked(struct srp *srp, void *nv)
{
void *ov;
@@ -54,7 +59,14 @@ srp_swap_locked(struct srp *srp, void *nv)
#define SRPL_FOREACH(_c, _srp, _sl, _ENTRY) \
SLIST_FOREACH(_c, _sl, _ENTRY)
-#define SRPL_EMPTY_LOCKED(_sl) SLIST_EMPTY(_sl)
+
+#define SRPL_EMPTY_LOCKED(_sl) SLIST_EMPTY(_sl)
+#define SRPL_FIRST_LOCKED(_sl) SLIST_FIRST(_sl)
+#define SRPL_NEXT_LOCKED(_e, _ENTRY) SLIST_NEXT(_e, _ENTRY)
+
+#define SRPL_FOREACH_LOCKED(_c, _sl, _ENTRY) \
+ SLIST_FOREACH(_c, _sl, _ENTRY)
+
#define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc) \
SLIST_FOREACH_SAFE(_c, _sl, _ENTRY, _tc)
@@ -64,6 +76,12 @@ srp_swap_locked(struct srp *srp, void *nv)
SLIST_INSERT_HEAD(_sl, _e, _ENTRY); \
} while (0)
+#define SRPL_INSERT_AFTER_LOCKED(_rc, _se, _e, _ENTRY) \
+ do { \
+ (_rc)->srpl_ref((_rc)->srpl_cookie, _e); \
+ SLIST_INSERT_AFTER(_se, _e, _ENTRY); \
+ } while (0)
+
#define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY) \
do { \
SLIST_REMOVE(_sl, _e, _type, _ENTRY); \
diff --git a/regress/sys/net/rtable/util.c b/regress/sys/net/rtable/util.c
index b2dee61fad4..ded34dbc5d1 100644
--- a/regress/sys/net/rtable/util.c
+++ b/regress/sys/net/rtable/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.5 2016/03/24 07:03:30 mpi Exp $ */
+/* $OpenBSD: util.c,v 1.6 2017/07/27 13:34:30 mpi Exp $ */
/*
* Copyright (c) 2015 Martin Pieuchot
@@ -15,6 +15,34 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * 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.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 THE PROJECT 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 "srp_compat.h"
@@ -399,3 +427,77 @@ inet_net_satop(sa_family_t af, struct sockaddr *sa, int plen, char *buf,
return (NULL);
}
}
+
+/* Give some jitter to hash, to avoid synchronization between routers. */
+static uint32_t rt_hashjitter;
+
+/*
+ * Originated from bridge_hash() in if_bridge.c
+ */
+#define mix(a, b, c) do { \
+ a -= b; a -= c; a ^= (c >> 13); \
+ b -= c; b -= a; b ^= (a << 8); \
+ c -= a; c -= b; c ^= (b >> 13); \
+ a -= b; a -= c; a ^= (c >> 12); \
+ b -= c; b -= a; b ^= (a << 16); \
+ c -= a; c -= b; c ^= (b >> 5); \
+ a -= b; a -= c; a ^= (c >> 3); \
+ b -= c; b -= a; b ^= (a << 10); \
+ c -= a; c -= b; c ^= (b >> 15); \
+} while (0)
+
+int
+rt_hash(struct rtentry *rt, struct sockaddr *dst, uint32_t *src)
+{
+ uint32_t a, b, c;
+
+ while (rt_hashjitter == 0)
+ rt_hashjitter = arc4random();
+
+ if (src == NULL)
+ return (-1);
+
+ a = b = 0x9e3779b9;
+ c = rt_hashjitter;
+
+ switch (dst->sa_family) {
+ case AF_INET:
+ {
+ struct sockaddr_in *sin;
+
+ sin = satosin(dst);
+ a += sin->sin_addr.s_addr;
+ b += (src != NULL) ? src[0] : 0;
+ mix(a, b, c);
+ break;
+ }
+#ifdef INET6
+ case AF_INET6:
+ {
+ struct sockaddr_in6 *sin6;
+
+ sin6 = satosin6(dst);
+ a += sin6->sin6_addr.s6_addr32[0];
+ b += sin6->sin6_addr.s6_addr32[2];
+ c += (src != NULL) ? src[0] : 0;
+ mix(a, b, c);
+ a += sin6->sin6_addr.s6_addr32[1];
+ b += sin6->sin6_addr.s6_addr32[3];
+ c += (src != NULL) ? src[1] : 0;
+ mix(a, b, c);
+ a += sin6->sin6_addr.s6_addr32[2];
+ b += sin6->sin6_addr.s6_addr32[1];
+ c += (src != NULL) ? src[2] : 0;
+ mix(a, b, c);
+ a += sin6->sin6_addr.s6_addr32[3];
+ b += sin6->sin6_addr.s6_addr32[0];
+ c += (src != NULL) ? src[3] : 0;
+ mix(a, b, c);
+ break;
+ }
+#endif /* INET6 */
+ }
+
+ return (c & 0xffff);
+}
+
diff --git a/regress/sys/net/rtable/util.h b/regress/sys/net/rtable/util.h
index 58f265f62a2..dedcb893b0e 100644
--- a/regress/sys/net/rtable/util.h
+++ b/regress/sys/net/rtable/util.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.h,v 1.1 2015/11/04 09:45:52 mpi Exp $ */
+/* $OpenBSD: util.h,v 1.2 2017/07/27 13:34:30 mpi Exp $ */
/*
* Copyright (c) 2015 Martin Pieuchot
@@ -30,3 +30,6 @@ int maskcmp(sa_family_t, struct sockaddr *, struct sockaddr *);
int inet_net_ptosa(sa_family_t, const char *, struct sockaddr *,
struct sockaddr *);
char *inet_net_satop(sa_family_t, struct sockaddr *, int, char *, size_t);
+
+#define satosin(sa) ((struct sockaddr_in *)(sa))
+#define satosin6(sa) ((struct sockaddr_in6 *)(sa))