* Insert PCB onto various hash lists. */
| 2739 | * Insert PCB onto various hash lists. |
| 2740 | */ |
| 2741 | static int |
| 2742 | in_pcbinshash_internal(struct inpcb *inp, struct mbuf *m) |
| 2743 | { |
| 2744 | struct inpcbhead *pcbhash; |
| 2745 | struct inpcbporthead *pcbporthash; |
| 2746 | struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; |
| 2747 | struct inpcbport *phd; |
| 2748 | u_int32_t hashkey_faddr; |
| 2749 | int so_options; |
| 2750 | |
| 2751 | INP_WLOCK_ASSERT(inp); |
| 2752 | INP_HASH_WLOCK_ASSERT(pcbinfo); |
| 2753 | |
| 2754 | KASSERT((inp->inp_flags & INP_INHASHLIST) == 0, |
| 2755 | ("in_pcbinshash: INP_INHASHLIST")); |
| 2756 | |
| 2757 | #ifdef INET6 |
| 2758 | if (inp->inp_vflag & INP_IPV6) |
| 2759 | hashkey_faddr = INP6_PCBHASHKEY(&inp->in6p_faddr); |
| 2760 | else |
| 2761 | #endif |
| 2762 | hashkey_faddr = inp->inp_faddr.s_addr; |
| 2763 | |
| 2764 | pcbhash = &pcbinfo->ipi_hashbase[INP_PCBHASH(hashkey_faddr, |
| 2765 | inp->inp_lport, inp->inp_fport, pcbinfo->ipi_hashmask)]; |
| 2766 | |
| 2767 | pcbporthash = &pcbinfo->ipi_porthashbase[ |
| 2768 | INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask)]; |
| 2769 | |
| 2770 | /* |
| 2771 | * Add entry to load balance group. |
| 2772 | * Only do this if SO_REUSEPORT_LB is set. |
| 2773 | */ |
| 2774 | so_options = inp_so_options(inp); |
| 2775 | if (so_options & SO_REUSEPORT_LB) { |
| 2776 | int ret = in_pcbinslbgrouphash(inp, M_NODOM); |
| 2777 | if (ret) { |
| 2778 | /* pcb lb group malloc fail (ret=ENOBUFS). */ |
| 2779 | return (ret); |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | /* |
| 2784 | * Go through port list and look for a head for this lport. |
| 2785 | */ |
| 2786 | CK_LIST_FOREACH(phd, pcbporthash, phd_hash) { |
| 2787 | if (phd->phd_port == inp->inp_lport) |
| 2788 | break; |
| 2789 | } |
| 2790 | /* |
| 2791 | * If none exists, malloc one and tack it on. |
| 2792 | */ |
| 2793 | if (phd == NULL) { |
| 2794 | phd = malloc(sizeof(struct inpcbport), M_PCB, M_NOWAIT); |
| 2795 | if (phd == NULL) { |
| 2796 | return (ENOBUFS); /* XXX */ |
| 2797 | } |
| 2798 | bzero(&phd->phd_epoch_ctx, sizeof(struct epoch_context)); |
no test coverage detected