1222748Srwatson/*- 2222748Srwatson * Copyright (c) 2010-2011 Juniper Networks, Inc. 3222748Srwatson * All rights reserved. 4222748Srwatson * 5222748Srwatson * This software was developed by Robert N. M. Watson under contract 6222748Srwatson * to Juniper Networks, Inc. 7222748Srwatson * 8222748Srwatson * Redistribution and use in source and binary forms, with or without 9222748Srwatson * modification, are permitted provided that the following conditions 10222748Srwatson * are met: 11222748Srwatson * 1. Redistributions of source code must retain the above copyright 12222748Srwatson * notice, this list of conditions and the following disclaimer. 13222748Srwatson * 2. Redistributions in binary form must reproduce the above copyright 14222748Srwatson * notice, this list of conditions and the following disclaimer in the 15222748Srwatson * documentation and/or other materials provided with the distribution. 16222748Srwatson * 17222748Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18222748Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19222748Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20222748Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21222748Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22222748Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23222748Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24222748Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25222748Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26222748Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27222748Srwatson * SUCH DAMAGE. 28222748Srwatson */ 29222748Srwatson 30222748Srwatson#include <sys/cdefs.h> 31222748Srwatson 32222748Srwatson__FBSDID("$FreeBSD$"); 33222748Srwatson 34222748Srwatson#include "opt_inet6.h" 35222748Srwatson 36222748Srwatson#include <sys/param.h> 37222748Srwatson#include <sys/mbuf.h> 38222748Srwatson 39222748Srwatson#include <netinet/in.h> 40222748Srwatson#include <netinet/in_pcb.h> 41222748Srwatson#ifdef INET6 42222748Srwatson#include <netinet6/in6_pcb.h> 43222748Srwatson#endif /* INET6 */ 44222748Srwatson 45222748Srwatson/* 46222748Srwatson * Given a hash of whatever the covered tuple might be, return a pcbgroup 47222748Srwatson * index. 48222748Srwatson */ 49222748Srwatsonstatic __inline u_int 50222748Srwatsonin6_pcbgroup_getbucket(struct inpcbinfo *pcbinfo, uint32_t hash) 51222748Srwatson{ 52222748Srwatson 53222748Srwatson return (hash % pcbinfo->ipi_npcbgroups); 54222748Srwatson} 55222748Srwatson 56222748Srwatson/* 57222748Srwatson * Map a (hashtype, hash) tuple into a connection group, or NULL if the hash 58222748Srwatson * information is insufficient to identify the pcbgroup. 59222748Srwatson */ 60222748Srwatsonstruct inpcbgroup * 61222748Srwatsonin6_pcbgroup_byhash(struct inpcbinfo *pcbinfo, u_int hashtype, uint32_t hash) 62222748Srwatson{ 63222748Srwatson 64222748Srwatson return (NULL); 65222748Srwatson} 66222748Srwatson 67222748Srwatsonstruct inpcbgroup * 68222748Srwatsonin6_pcbgroup_bymbuf(struct inpcbinfo *pcbinfo, struct mbuf *m) 69222748Srwatson{ 70222748Srwatson 71222748Srwatson return (in6_pcbgroup_byhash(pcbinfo, M_HASHTYPE_GET(m), 72222748Srwatson m->m_pkthdr.flowid)); 73222748Srwatson} 74222748Srwatson 75222748Srwatsonstruct inpcbgroup * 76222748Srwatsonin6_pcbgroup_bytuple(struct inpcbinfo *pcbinfo, const struct in6_addr *laddrp, 77222748Srwatson u_short lport, const struct in6_addr *faddrp, u_short fport) 78222748Srwatson{ 79222748Srwatson uint32_t hash; 80222748Srwatson 81222748Srwatson switch (pcbinfo->ipi_hashfields) { 82222748Srwatson case IPI_HASHFIELDS_4TUPLE: 83222748Srwatson hash = faddrp->s6_addr32[3] ^ fport; 84222748Srwatson break; 85222748Srwatson 86222748Srwatson case IPI_HASHFIELDS_2TUPLE: 87222748Srwatson hash = faddrp->s6_addr32[3] ^ laddrp->s6_addr32[3]; 88222748Srwatson break; 89222748Srwatson 90222748Srwatson default: 91222748Srwatson hash = 0; 92222748Srwatson } 93222748Srwatson return (&pcbinfo->ipi_pcbgroups[in6_pcbgroup_getbucket(pcbinfo, 94222748Srwatson hash)]); 95222748Srwatson} 96222748Srwatson 97222748Srwatsonstruct inpcbgroup * 98222748Srwatsonin6_pcbgroup_byinpcb(struct inpcb *inp) 99222748Srwatson{ 100222748Srwatson 101222748Srwatson return (in6_pcbgroup_bytuple(inp->inp_pcbinfo, &inp->in6p_laddr, 102222748Srwatson inp->inp_lport, &inp->in6p_faddr, inp->inp_fport)); 103222748Srwatson} 104