1 /* $NetBSD: in6_pcb.h,v 1.52 2020/09/08 14:12:57 christos Exp $ */ 2 /* $KAME: in6_pcb.h,v 1.45 2001/02/09 05:59:46 itojun Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 /* 34 * Copyright (c) 1982, 1986, 1990, 1993 35 * The Regents of the University of California. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. Neither the name of the University nor the names of its contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 62 */ 63 64 #ifndef _NETINET6_IN6_PCB_H_ 65 #define _NETINET6_IN6_PCB_H_ 66 67 #include <sys/queue.h> 68 #include <netinet/in_pcb_hdr.h> 69 #include <netinet/ip6.h> 70 71 /* 72 * Common structure pcb for internet protocol implementation. 73 * Here are stored pointers to local and foreign host table 74 * entries, local and foreign socket numbers, and pointers 75 * up (to a socket structure) and down (to a protocol-specific) 76 * control block. 77 */ 78 struct icmp6_filter; 79 80 struct in6pcb { 81 struct inpcb_hdr in6p_head; 82 #define in6p_hash in6p_head.inph_hash 83 #define in6p_queue in6p_head.inph_queue 84 #define in6p_af in6p_head.inph_af 85 #define in6p_ppcb in6p_head.inph_ppcb 86 #define in6p_state in6p_head.inph_state 87 #define in6p_portalgo in6p_head.inph_portalgo 88 #define in6p_socket in6p_head.inph_socket 89 #define in6p_table in6p_head.inph_table 90 #define in6p_sp in6p_head.inph_sp 91 struct route in6p_route; /* placeholder for routing entry */ 92 u_int16_t in6p_fport; /* foreign port */ 93 u_int16_t in6p_lport; /* local port */ 94 u_int32_t in6p_flowinfo; /* priority and flowlabel */ 95 int in6p_flags; /* generic IP6/datagram flags */ 96 int in6p_hops; /* default hop limit */ 97 struct ip6_hdr in6p_ip6; /* header prototype */ 98 struct mbuf *in6p_options; /* IP6 options */ 99 struct ip6_pktopts *in6p_outputopts; /* IP6 options for outgoing packets */ 100 struct ip6_moptions *in6p_moptions; /* IP6 multicast options */ 101 struct icmp6_filter *in6p_icmp6filt; 102 int in6p_cksum; /* IPV6_CHECKSUM setsockopt */ 103 bool in6p_bindportonsend; 104 struct ip_moptions *in6p_v4moptions;/* IP4 multicast options */ 105 pcb_overudp_cb_t in6p_overudp_cb; 106 void *in6p_overudp_arg; 107 }; 108 109 #define in6p_faddr in6p_ip6.ip6_dst 110 #define in6p_laddr in6p_ip6.ip6_src 111 112 #define in6p_lock(in6p) solock((in6p)->in6p_socket) 113 #define in6p_unlock(in6p) sounlock((in6p)->in6p_socket) 114 #define in6p_locked(in6p) solocked((in6p)->in6p_socket) 115 116 /* states in inp_state: */ 117 #define IN6P_ATTACHED INP_ATTACHED 118 #define IN6P_BOUND INP_BOUND 119 #define IN6P_CONNECTED INP_CONNECTED 120 121 /* 122 * Flags in in6p_flags 123 * We define KAME's original flags in higher 16 bits as much as possible 124 * for compatibility with *bsd*s. 125 */ 126 #define IN6P_RECVOPTS 0x00001000 /* receive incoming IP6 options */ 127 #define IN6P_RECVRETOPTS 0x00002000 /* receive IP6 options for reply */ 128 #define IN6P_RECVDSTADDR 0x00004000 /* receive IP6 dst address */ 129 #define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */ 130 #define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */ 131 #define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */ 132 #define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */ 133 #define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */ 134 #define IN6P_RTHDR 0x00100000 /* receive routing header */ 135 #define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */ 136 #define IN6P_TCLASS 0x00400000 /* traffic class */ 137 #define IN6P_BINDANY 0x00800000 /* allow bind to any address */ 138 #define IN6P_HIGHPORT 0x01000000 /* user wants "high" port binding */ 139 #define IN6P_LOWPORT 0x02000000 /* user wants "low" port binding */ 140 #define IN6P_ANONPORT 0x04000000 /* port chosen for user */ 141 #define IN6P_FAITH 0x08000000 /* accept FAITH'ed connections */ 142 /* XXX should move to an UDP control block */ 143 #define IN6P_ESPINUDP INP_ESPINUDP /* ESP over UDP for NAT-T */ 144 145 #define IN6P_RFC2292 0x40000000 /* RFC2292 */ 146 #define IN6P_MTU 0x80000000 /* use minimum MTU */ 147 148 #define IN6P_CONTROLOPTS (IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ 149 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ 150 IN6P_TCLASS|IN6P_RFC2292|\ 151 IN6P_MTU) 152 153 #ifdef _KERNEL 154 /* compute hash value for foreign and local in6_addr and port */ 155 #define IN6_HASH(faddr, fport, laddr, lport) \ 156 (((faddr)->s6_addr32[0] ^ (faddr)->s6_addr32[1] ^ \ 157 (faddr)->s6_addr32[2] ^ (faddr)->s6_addr32[3] ^ \ 158 (laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^ \ 159 (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3]) \ 160 + (fport) + (lport)) 161 162 #define sotoin6pcb(so) ((struct in6pcb *)(so)->so_pcb) 163 164 void in6_losing(struct in6pcb *); 165 void in6_pcbinit(struct inpcbtable *, int, int); 166 int in6_pcballoc(struct socket *, void *); 167 int in6_pcbbind(void *, struct sockaddr_in6 *, struct lwp *); 168 int in6_pcbconnect(void *, struct sockaddr_in6 *, struct lwp *); 169 void in6_pcbdetach(struct in6pcb *); 170 void in6_pcbdisconnect(struct in6pcb *); 171 struct in6pcb *in6_pcblookup_port(struct inpcbtable *, struct in6_addr *, 172 u_int, int, struct vestigial_inpcb *); 173 int in6_pcbnotify(struct inpcbtable *, const struct sockaddr *, 174 u_int, const struct sockaddr *, u_int, int, void *, 175 void (*)(struct in6pcb *, int)); 176 void in6_pcbpurgeif0(struct inpcbtable *, struct ifnet *); 177 void in6_pcbpurgeif(struct inpcbtable *, struct ifnet *); 178 void in6_pcbstate(struct in6pcb *, int); 179 void in6_rtchange(struct in6pcb *, int); 180 void in6_setpeeraddr(struct in6pcb *, struct sockaddr_in6 *); 181 void in6_setsockaddr(struct in6pcb *, struct sockaddr_in6 *); 182 183 /* in in6_src.c */ 184 int in6_selecthlim(struct in6pcb *, struct ifnet *); 185 int in6_selecthlim_rt(struct in6pcb *); 186 int in6_pcbsetport(struct sockaddr_in6 *, struct in6pcb *, struct lwp *); 187 188 extern struct rtentry * 189 in6_pcbrtentry(struct in6pcb *); 190 extern void 191 in6_pcbrtentry_unref(struct rtentry *, struct in6pcb *); 192 extern struct in6pcb *in6_pcblookup_connect(struct inpcbtable *, 193 const struct in6_addr *, u_int, const struct in6_addr *, u_int, int, 194 struct vestigial_inpcb *); 195 extern struct in6pcb *in6_pcblookup_bind(struct inpcbtable *, 196 const struct in6_addr *, u_int, int); 197 198 static inline void 199 in6_pcb_register_overudp_cb(struct in6pcb *in6p, pcb_overudp_cb_t cb, void *arg) 200 { 201 202 in6p->in6p_overudp_cb = cb; 203 in6p->in6p_overudp_arg = arg; 204 } 205 #endif /* _KERNEL */ 206 207 #endif /* !_NETINET6_IN6_PCB_H_ */ 208