From 8a5c0ed67e23e4c3539d73d5defc2d423a461f38 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sat, 21 Mar 2009 18:38:44 +0800 Subject: [PATCH] ip_demux: Add ip_mport_pktinfo() to map IP packets using packet info --- sys/netinet/ip_demux.c | 41 +++++++++++++++++++++++++++++++++++++++++ sys/netinet/ip_input.c | 2 +- sys/netinet/ip_var.h | 3 +++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/sys/netinet/ip_demux.c b/sys/netinet/ip_demux.c index e7908cdb48..b23fa7a8f7 100644 --- a/sys/netinet/ip_demux.c +++ b/sys/netinet/ip_demux.c @@ -338,6 +338,47 @@ ip_mport_in(struct mbuf **mptr) } /* + * Map a packet to a protocol processing thread and return the thread's port. + * Unlike ip_mport(), the packet content is not accessed. The packet info + * (pi) and the hash of the packet (m_pkthdr.hash) is used instead. NULL is + * returned if the packet info does not contain enough information. + * + * Caller has already made sure that m_pkthdr.hash is valid, i.e. m_flags + * has M_HASH set. + */ +lwkt_port_t +ip_mport_pktinfo(const struct pktinfo *pi, struct mbuf *m) +{ + lwkt_port_t port; + + KASSERT(m->m_pkthdr.hash < ncpus2, + ("invalid packet hash %#x\n", m->m_pkthdr.hash)); + + /* + * XXX generic packet handling defrag on CPU 0 for now. + */ + if (pi->pi_flags & PKTINFO_FLAG_FRAG) { + m->m_pkthdr.hash = 0; + return &netisr_cpu[0].td_msgport; + } + + switch (pi->pi_l3proto) { + case IPPROTO_TCP: + port = &tcp_thread[m->m_pkthdr.hash].td_msgport; + break; + + case IPPROTO_UDP: + port = &udp_thread[m->m_pkthdr.hash].td_msgport; + break; + + default: + port = NULL; + break; + } + return port; +} + +/* * Map a TCP socket to a protocol processing thread. */ lwkt_port_t diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 09413052da..b7365ef711 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -392,7 +392,7 @@ ip_init(void) flags = NETISR_FLAG_NOTMPSAFE; } #endif - netisr_register(NETISR_IP, ip_mport_in, pktinfo_portfn_notsupp, + netisr_register(NETISR_IP, ip_mport_in, ip_mport_pktinfo, ip_input_handler, flags); } diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 4f6669be54..02776b36cd 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -178,6 +178,7 @@ struct inpcb; struct route; struct sockopt; struct lwkt_port; +struct pktinfo; extern u_short ip_id; /* ip packet ctr, for ids */ extern int ip_defttl; /* default IP ttl */ @@ -205,6 +206,8 @@ struct lwkt_port * ip_mport_in(struct mbuf **); struct lwkt_port * ip_mport(struct mbuf **, int); +struct lwkt_port * + ip_mport_pktinfo(const struct pktinfo *, struct mbuf *); boolean_t ip_lengthcheck(struct mbuf **); int ip_output(struct mbuf *, -- 2.11.4.GIT