From 48242f4767c5268dbf0a23b3be42fafb34d7e25f Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sun, 24 Jul 2011 15:24:34 +0800 Subject: [PATCH] ethernet: Add ether_demux(), which will send the packet to the correct netisr It is intended to be used by the function which does not know whether the current thread is the correct netisr for the ethernet packet or not. Currently only ng_ether uses this function, which incorrectly called ether_demux_oncpu(). The other two callers of ether_demux_oncpu() are already on the correct netisr. This paves the way to avoid requeuing the packet to the current netisr in the ether_demux_oncpu(). --- sys/net/if_ethersubr.c | 34 ++++++++++++++++++++++++++++++++++ sys/net/if_var.h | 1 + sys/netgraph/ether/ng_ether.c | 7 +------ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index c666ab4774..e6300c7a33 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1709,4 +1709,38 @@ ether_characterize(struct mbuf **m0) return isr; } +static void +ether_demux_handler(netmsg_t nmsg) +{ + struct netmsg_packet *nmp = &nmsg->packet; /* actual size */ + struct ifnet *ifp; + struct mbuf *m; + + m = nmp->nm_packet; + M_ASSERTPKTHDR(m); + ifp = m->m_pkthdr.rcvif; + + ether_demux_oncpu(ifp, m); +} + +void +ether_demux(struct mbuf *m) +{ + struct netmsg_packet *pmsg; + int isr; + + isr = ether_characterize(&m); + if (m == NULL) + return; + + KKASSERT(m->m_flags & M_HASH); + pmsg = &m->m_hdr.mh_netmsg; + netmsg_init(&pmsg->base, NULL, &netisr_apanic_rport, + 0, ether_demux_handler); + pmsg->nm_packet = m; + pmsg->base.lmsg.u.ms_result = isr; + + lwkt_sendmsg(cpu_portfn(m->m_pkthdr.hash), &pmsg->base.lmsg); +} + MODULE_VERSION(ether, 1); diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 114eb5f9dd..e5a6efbe3f 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -740,6 +740,7 @@ void ether_ifattach(struct ifnet *, uint8_t *, struct lwkt_serialize *); void ether_ifattach_bpf(struct ifnet *, uint8_t *, u_int, u_int, struct lwkt_serialize *); void ether_ifdetach(struct ifnet *); +void ether_demux(struct mbuf *); void ether_demux_oncpu(struct ifnet *, struct mbuf *); void ether_reinput_oncpu(struct ifnet *, struct mbuf *, int); void ether_input_chain(struct ifnet *, struct mbuf *, diff --git a/sys/netgraph/ether/ng_ether.c b/sys/netgraph/ether/ng_ether.c index 682c63b3ab..e00a5b866c 100644 --- a/sys/netgraph/ether/ng_ether.c +++ b/sys/netgraph/ether/ng_ether.c @@ -630,13 +630,8 @@ ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta) m->m_pkthdr.rcvif = priv->ifp; - /* - * XXX - * Since frame processing is run in netisr0, - * 'm' may _not_ even on its target CPU. - */ /* Route packet back in */ - ether_demux_oncpu(priv->ifp, m); + ether_demux(m); return (0); } -- 2.11.4.GIT