Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Hook up lltable/llentry with the kernel (and rumpkernel)
details: https://anonhg.NetBSD.org/src/rev/d6cb829e27c4
branches: trunk
changeset: 340316:d6cb829e27c4
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Mon Aug 31 08:02:44 2015 +0000
description:
Hook up lltable/llentry with the kernel (and rumpkernel)
It is built and initialized on bootup, but there is no user for now.
Most codes in in.c are imported from FreeBSD as well as lltable/llentry.
diffstat:
sys/kern/init_main.c | 6 +-
sys/net/files.net | 3 +-
sys/net/if.c | 6 +-
sys/net/if.h | 27 ++-
sys/net/route.h | 3 +-
sys/netinet/in.c | 390 +++++++++++++++++++++++++++++++-
sys/netinet/in_selsrc.c | 11 +-
sys/netinet/in_selsrc.h | 3 +
sys/netinet/in_var.h | 14 +-
sys/rump/net/lib/libnet/Makefile | 3 +-
sys/rump/net/lib/libnet/net_component.c | 6 +-
11 files changed, 453 insertions(+), 19 deletions(-)
diffs (truncated from 728 to 300 lines):
diff -r 35f3e2025617 -r d6cb829e27c4 sys/kern/init_main.c
--- a/sys/kern/init_main.c Mon Aug 31 08:00:44 2015 +0000
+++ b/sys/kern/init_main.c Mon Aug 31 08:02:44 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.467 2015/05/06 15:57:08 hannken Exp $ */
+/* $NetBSD: init_main.c,v 1.468 2015/08/31 08:02:44 ozaki-r Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.467 2015/05/06 15:57:08 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.468 2015/08/31 08:02:44 ozaki-r Exp $");
#include "opt_ddb.h"
#include "opt_ipsec.h"
@@ -228,6 +228,7 @@
#include <net/bpf.h>
#include <net/if.h>
#include <net/raw_cb.h>
+#include <net/if_llatbl.h>
#include <prop/proplib.h>
@@ -565,6 +566,7 @@
*/
s = splnet();
ifinit();
+ lltableinit();
domaininit(true);
if_attachdomain();
splx(s);
diff -r 35f3e2025617 -r d6cb829e27c4 sys/net/files.net
--- a/sys/net/files.net Mon Aug 31 08:00:44 2015 +0000
+++ b/sys/net/files.net Mon Aug 31 08:02:44 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.net,v 1.6 2015/06/01 00:15:07 roy Exp $
+# $NetBSD: files.net,v 1.7 2015/08/31 08:02:44 ozaki-r Exp $
# XXX CLEANUP
define net
@@ -22,6 +22,7 @@
file net/if_gre.c gre needs-flag
file net/if_hippisubr.c hippi needs-flag
file net/if_ieee1394subr.c ieee1394
+file net/if_llatbl.c ether
file net/if_loop.c loop
file net/if_media.c net
file net/if_mpls.c ifmpls needs-flag
diff -r 35f3e2025617 -r d6cb829e27c4 sys/net/if.c
--- a/sys/net/if.c Mon Aug 31 08:00:44 2015 +0000
+++ b/sys/net/if.c Mon Aug 31 08:02:44 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.317 2015/07/17 02:21:08 ozaki-r Exp $ */
+/* $NetBSD: if.c,v 1.318 2015/08/31 08:02:44 ozaki-r Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.317 2015/07/17 02:21:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.318 2015/08/31 08:02:44 ozaki-r Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -615,6 +615,8 @@
(void)pfil_run_hooks(if_pfil,
(struct mbuf **)PFIL_IFNET_ATTACH, ifp, PFIL_IFNET);
+ IF_AFDATA_LOCK_INIT(ifp);
+
if_getindex(ifp);
}
diff -r 35f3e2025617 -r d6cb829e27c4 sys/net/if.h
--- a/sys/net/if.h Mon Aug 31 08:00:44 2015 +0000
+++ b/sys/net/if.h Mon Aug 31 08:02:44 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.h,v 1.190 2015/05/18 06:38:59 martin Exp $ */
+/* $NetBSD: if.h,v 1.191 2015/08/31 08:02:44 ozaki-r Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -213,6 +213,7 @@
#include <sys/condvar.h>
#include <sys/percpu.h>
#include <sys/callout.h>
+#include <sys/rwlock.h>
struct ifnet_lock {
kmutex_t il_lock; /* Protects the critical section. */
@@ -244,6 +245,7 @@
struct bridge_softc;
struct bridge_iflist;
struct callout;
+struct krwlock;
typedef struct ifnet {
void *if_softc; /* lower-level data for this if */
@@ -345,6 +347,7 @@
#ifdef _KERNEL /* XXX kvm(3) */
struct callout *if_slowtimo_ch;
#endif
+ struct krwlock *if_afdata_lock;
} ifnet_t;
#define if_mtu if_data.ifi_mtu
@@ -434,6 +437,28 @@
"\23TSO6" \
"\24LRO" \
+#define IF_AFDATA_LOCK_INIT(ifp) \
+ do {(ifp)->if_afdata_lock = rw_obj_alloc();} while (0)
+
+#define IF_AFDATA_WLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_WRITER)
+#define IF_AFDATA_RLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_READER)
+#define IF_AFDATA_WUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock)
+#define IF_AFDATA_RUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock)
+#define IF_AFDATA_LOCK(ifp) IF_AFDATA_WLOCK(ifp)
+#define IF_AFDATA_UNLOCK(ifp) IF_AFDATA_WUNLOCK(ifp)
+#define IF_AFDATA_TRYLOCK(ifp) rw_tryenter((ifp)->if_afdata_lock, RW_WRITER)
+#define IF_AFDATA_DESTROY(ifp) rw_destroy((ifp)->if_afdata_lock)
+
+#define IF_AFDATA_LOCK_ASSERT(ifp) \
+ KASSERT(rw_lock_held((ifp)->if_afdata_lock))
+#define IF_AFDATA_RLOCK_ASSERT(ifp) \
+ KASSERT(rw_read_held((ifp)->if_afdata_lock))
+#define IF_AFDATA_WLOCK_ASSERT(ifp) \
+ KASSERT(rw_write_held((ifp)->if_afdata_lock))
+#define IF_AFDATA_UNLOCK_ASSERT(ifp) \
+ KASSERT(!rw_lock_head((ifp)->if_afdata_lock))
+
+
#define IFQ_LOCK(_ifq) if ((_ifq)->ifq_lock) mutex_enter((_ifq)->ifq_lock)
#define IFQ_UNLOCK(_ifq) if ((_ifq)->ifq_lock) mutex_exit((_ifq)->ifq_lock)
diff -r 35f3e2025617 -r d6cb829e27c4 sys/net/route.h
--- a/sys/net/route.h Mon Aug 31 08:00:44 2015 +0000
+++ b/sys/net/route.h Mon Aug 31 08:02:44 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: route.h,v 1.94 2015/08/31 06:25:15 ozaki-r Exp $ */
+/* $NetBSD: route.h,v 1.95 2015/08/31 08:02:44 ozaki-r Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -148,6 +148,7 @@
#define RTF_CLONING 0x100 /* generate new routes on use */
#define RTF_XRESOLVE 0x200 /* external daemon resolves name */
#define RTF_LLINFO 0x400 /* generated by ARP or NDP */
+#define RTF_LLDATA 0x400 /* used by apps to add/del L2 entries */
#define RTF_STATIC 0x800 /* manually added */
#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
#define RTF_CLONED 0x2000 /* this is a cloned route */
diff -r 35f3e2025617 -r d6cb829e27c4 sys/netinet/in.c
--- a/sys/netinet/in.c Mon Aug 31 08:00:44 2015 +0000
+++ b/sys/netinet/in.c Mon Aug 31 08:02:44 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in.c,v 1.157 2015/08/24 22:21:26 pooka Exp $ */
+/* $NetBSD: in.c,v 1.158 2015/08/31 08:02:44 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.157 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.158 2015/08/31 08:02:44 ozaki-r Exp $");
#include "arp.h"
@@ -113,6 +113,7 @@
#include <sys/proc.h>
#include <sys/syslog.h>
#include <sys/kauth.h>
+#include <sys/kmem.h>
#include <sys/cprng.h>
@@ -121,6 +122,9 @@
#include <net/pfil.h>
#include <net/if_ether.h>
+#include <net/if_types.h>
+#include <net/if_llatbl.h>
+#include <net/if_dl.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
@@ -129,6 +133,7 @@
#include <netinet/ip_var.h>
#include <netinet/in_ifattach.h>
#include <netinet/in_pcb.h>
+#include <netinet/in_selsrc.h>
#include <netinet/if_inarp.h>
#include <netinet/ip_mroute.h>
#include <netinet/igmp_var.h>
@@ -1529,6 +1534,333 @@
return satosin(&ia->ia_addr);
}
+struct in_llentry {
+ struct llentry base;
+};
+
+#define IN_LLTBL_DEFAULT_HSIZE 32
+#define IN_LLTBL_HASH(k, h) \
+ (((((((k >> 8) ^ k) >> 8) ^ k) >> 8) ^ k) & ((h) - 1))
+
+/*
+ * Do actual deallocation of @lle.
+ * Called by LLE_FREE_LOCKED when number of references
+ * drops to zero.
+ */
+static void
+in_lltable_destroy_lle(struct llentry *lle)
+{
+
+ LLE_WUNLOCK(lle);
+ LLE_LOCK_DESTROY(lle);
+ kmem_intr_free(lle, sizeof(*lle));
+}
+
+static struct llentry *
+in_lltable_new(struct in_addr addr4, u_int flags)
+{
+ struct in_llentry *lle;
+
+ lle = kmem_intr_zalloc(sizeof(*lle), KM_NOSLEEP);
+ if (lle == NULL) /* NB: caller generates msg */
+ return NULL;
+
+ /*
+ * For IPv4 this will trigger "arpresolve" to generate
+ * an ARP request.
+ */
+ lle->base.la_expire = time_uptime; /* mark expired */
+ lle->base.r_l3addr.addr4 = addr4;
+ lle->base.lle_refcnt = 1;
+ lle->base.lle_free = in_lltable_destroy_lle;
+ LLE_LOCK_INIT(&lle->base);
+ callout_init(&lle->base.la_timer, 1);
+
+ return (&lle->base);
+}
+
+#define IN_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
+ (((ntohl((d).s_addr) ^ (a)->sin_addr.s_addr) & (m)->sin_addr.s_addr)) == 0 )
+
+static int
+in_lltable_match_prefix(const struct sockaddr *prefix,
+ const struct sockaddr *mask, u_int flags, struct llentry *lle)
+{
+ const struct sockaddr_in *pfx = (const struct sockaddr_in *)prefix;
+ const struct sockaddr_in *msk = (const struct sockaddr_in *)mask;
+
+ /*
+ * (flags & LLE_STATIC) means deleting all entries
+ * including static ARP entries.
+ */
+ if (IN_ARE_MASKED_ADDR_EQUAL(lle->r_l3addr.addr4, pfx, msk) &&
+ ((flags & LLE_STATIC) || !(lle->la_flags & LLE_STATIC)))
+ return (1);
+
+ return (0);
+}
+
+static void
+in_lltable_free_entry(struct lltable *llt, struct llentry *lle)
+{
+ struct ifnet *ifp;
+ size_t pkts_dropped;
+
+ LLE_WLOCK_ASSERT(lle);
+ KASSERT(llt != NULL);
+
+ /* Unlink entry from table if not already */
+ if ((lle->la_flags & LLE_LINKED) != 0) {
+ ifp = llt->llt_ifp;
+ IF_AFDATA_WLOCK_ASSERT(ifp);
+ lltable_unlink_entry(llt, lle);
+ }
+
+ /* cancel timer */
+ if (callout_stop(&lle->lle_timer))
+ LLE_REMREF(lle);
+
+ /* Drop hold queue */
+ pkts_dropped = llentry_free(lle);
+#ifdef __FreeBSD__
+ ARPSTAT_ADD(dropped, pkts_dropped);
+#else
+ (void) pkts_dropped; /* FIXME */
+#endif
+}
+
Home |
Main Index |
Thread Index |
Old Index