/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the project nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*30* $KAME: ip6_var.h,v 1.62 2001/05/03 14:51:48 itojun Exp $31*/3233/*-34* Copyright (c) 1982, 1986, 199335* The Regents of the University of California. All rights reserved.36*37* Redistribution and use in source and binary forms, with or without38* modification, are permitted provided that the following conditions39* are met:40* 1. Redistributions of source code must retain the above copyright41* notice, this list of conditions and the following disclaimer.42* 2. Redistributions in binary form must reproduce the above copyright43* notice, this list of conditions and the following disclaimer in the44* documentation and/or other materials provided with the distribution.45* 3. Neither the name of the University nor the names of its contributors46* may be used to endorse or promote products derived from this software47* without specific prior written permission.48*49* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND50* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE51* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE52* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE53* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL54* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS55* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)56* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT57* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY58* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF59* SUCH DAMAGE.60*/6162#ifndef _NETINET6_IP6_VAR_H_63#define _NETINET6_IP6_VAR_H_6465#include <sys/epoch.h>6667#ifdef _KERNEL68struct ip6asfrag; /* frag6.c */69TAILQ_HEAD(ip6fraghead, ip6asfrag);7071/*72* IP6 reassembly queue structure. Each fragment73* being reassembled is attached to one of these structures.74*/75struct ip6q {76struct ip6fraghead ip6q_frags;77u_int32_t ip6q_ident;78u_int8_t ip6q_nxt;79u_int8_t ip6q_ecn;80u_int16_t ip6q_ttl;81struct in6_addr ip6q_src, ip6q_dst;82TAILQ_ENTRY(ip6q) ip6q_tq;83int ip6q_unfrglen; /* len of unfragmentable part */84int ip6q_nfrag; /* # of fragments */85struct label *ip6q_label;86};87#endif /* _KERNEL */8889/*90* IP6 reinjecting structure.91*/92struct ip6_direct_ctx {93uint32_t ip6dc_nxt; /* next header to process */94uint32_t ip6dc_off; /* offset to next header */95};9697#if defined(_NETINET6_IN6_VAR_H_) && defined(_KERNEL)98/*99* Structure attached to inpcb.in6p_moptions and100* passed to ip6_output when IPv6 multicast options are in use.101* This structure is lazy-allocated.102*/103struct ip6_moptions {104struct ifnet *im6o_multicast_ifp; /* ifp for outgoing multicasts */105u_char im6o_multicast_hlim; /* hoplimit for outgoing multicasts */106u_char im6o_multicast_loop; /* 1 >= hear sends if a member */107struct ip6_mfilter_head im6o_head; /* group membership list */108};109#else110struct ip6_moptions;111#endif112/*113* Control options for outgoing packets114*/115116/* Routing header related info */117struct ip6po_rhinfo {118struct ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */119struct route_in6 ip6po_rhi_route; /* Route to the 1st hop */120};121#define ip6po_rthdr ip6po_rhinfo.ip6po_rhi_rthdr122#define ip6po_route ip6po_rhinfo.ip6po_rhi_route123124/* Nexthop related info */125struct ip6po_nhinfo {126struct sockaddr *ip6po_nhi_nexthop;127struct route_in6 ip6po_nhi_route; /* Route to the nexthop */128};129#define ip6po_nexthop ip6po_nhinfo.ip6po_nhi_nexthop130#define ip6po_nextroute ip6po_nhinfo.ip6po_nhi_route131132/*133* Note that fields with valid data must be flagged in ip6po_valid.134* This is done to reduce cache misses in ip6_output(). Before135* ip6po_valid, ip6_output needed to check all the individual fields136* of ip6_pktopts needed to be checked themselves, and they are spread137* across 4 cachelines. ip6_output() is currently the only consumer of138* these flags, as it is in the critical path of every packet sent.139*/140struct ip6_pktopts {141uint32_t ip6po_valid;142#define IP6PO_VALID_HLIM 0x0001143#define IP6PO_VALID_PKTINFO 0x0002144#define IP6PO_VALID_NHINFO 0x0004145#define IP6PO_VALID_HBH 0x0008146#define IP6PO_VALID_DEST1 0x0010147#define IP6PO_VALID_RHINFO 0x0020148#define IP6PO_VALID_DEST2 0x0040149#define IP6PO_VALID_TC 0x0080150151int ip6po_hlim; /* Hoplimit for outgoing packets */152int ip6po_tclass; /* traffic class */153154int ip6po_minmtu; /* fragment vs PMTU discovery policy */155#define IP6PO_MINMTU_MCASTONLY -1 /* default; send at min MTU for multicast*/156#define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */157#define IP6PO_MINMTU_ALL 1 /* always send at min MTU */158159int ip6po_prefer_tempaddr; /* whether temporary addresses are160preferred as source address */161#define IP6PO_TEMPADDR_SYSTEM -1 /* follow the system default */162#define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */163#define IP6PO_TEMPADDR_PREFER 1 /* prefer temporary address */164165int ip6po_flags;166#if 0 /* parameters in this block is obsolete. do not reuse the values. */167#define IP6PO_REACHCONF 0x01 /* upper-layer reachability confirmation. */168#define IP6PO_MINMTU 0x02 /* use minimum MTU (IPV6_USE_MIN_MTU) */169#endif170#define IP6PO_DONTFRAG 0x04 /* disable fragmentation (IPV6_DONTFRAG) */171#define IP6PO_USECOA 0x08 /* use care of address */172173struct mbuf *ip6po_m; /* Pointer to mbuf storing the data */174175/* Outgoing IF/address information */176struct in6_pktinfo *ip6po_pktinfo;177178/* Next-hop address information */179struct ip6po_nhinfo ip6po_nhinfo;180181struct ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */182183/* Destination options header (before a routing header) */184struct ip6_dest *ip6po_dest1;185186/* Routing header related info. */187struct ip6po_rhinfo ip6po_rhinfo;188189/* Destination options header (after a routing header) */190struct ip6_dest *ip6po_dest2;191};192193/*194* Control options for incoming packets195*/196197struct ip6stat {198uint64_t ip6s_total; /* total packets received */199uint64_t ip6s_tooshort; /* packet too short */200uint64_t ip6s_toosmall; /* not enough data */201uint64_t ip6s_fragments; /* fragments received */202uint64_t ip6s_fragdropped; /* frags dropped(dups, out of space) */203uint64_t ip6s_fragtimeout; /* fragments timed out */204uint64_t ip6s_fragoverflow; /* fragments that exceeded limit */205uint64_t ip6s_forward; /* packets forwarded */206uint64_t ip6s_cantforward; /* packets rcvd for unreachable dest */207uint64_t ip6s_redirectsent; /* packets forwarded on same net */208uint64_t ip6s_delivered; /* datagrams delivered to upper level*/209uint64_t ip6s_localout; /* total ip packets generated here */210uint64_t ip6s_odropped; /* lost packets due to nobufs, etc. */211uint64_t ip6s_reassembled; /* total packets reassembled ok */212uint64_t ip6s_atomicfrags; /* atomic fragments */213uint64_t ip6s_fragmented; /* datagrams successfully fragmented */214uint64_t ip6s_ofragments; /* output fragments created */215uint64_t ip6s_cantfrag; /* don't fragment flag was set, etc. */216uint64_t ip6s_badoptions; /* error in option processing */217uint64_t ip6s_noroute; /* packets discarded due to no route */218uint64_t ip6s_badvers; /* ip6 version != 6 */219uint64_t ip6s_rawout; /* total raw ip packets generated */220uint64_t ip6s_badscope; /* scope error */221uint64_t ip6s_notmember; /* don't join this multicast group */222#define IP6S_HDRCNT 256 /* headers count */223uint64_t ip6s_nxthist[IP6S_HDRCNT]; /* next header history */224uint64_t ip6s_m1; /* one mbuf */225#define IP6S_M2MMAX 32226uint64_t ip6s_m2m[IP6S_M2MMAX]; /* two or more mbuf */227uint64_t ip6s_mext1; /* one ext mbuf */228uint64_t ip6s_mext2m; /* two or more ext mbuf */229uint64_t ip6s_exthdrtoolong; /* ext hdr are not contiguous */230uint64_t ip6s_nogif; /* no match gif found */231uint64_t ip6s_toomanyhdr; /* discarded due to too many headers */232233/*234* statistics for improvement of the source address selection235* algorithm:236* XXX: hardcoded 16 = # of ip6 multicast scope types + 1237*/238#define IP6S_RULESMAX 16239#define IP6S_SCOPECNT 16240/* number of times that address selection fails */241uint64_t ip6s_sources_none;242/* number of times that an address on the outgoing I/F is chosen */243uint64_t ip6s_sources_sameif[IP6S_SCOPECNT];244/* number of times that an address on a non-outgoing I/F is chosen */245uint64_t ip6s_sources_otherif[IP6S_SCOPECNT];246/*247* number of times that an address that has the same scope248* from the destination is chosen.249*/250uint64_t ip6s_sources_samescope[IP6S_SCOPECNT];251/*252* number of times that an address that has a different scope253* from the destination is chosen.254*/255uint64_t ip6s_sources_otherscope[IP6S_SCOPECNT];256/* number of times that a deprecated address is chosen */257uint64_t ip6s_sources_deprecated[IP6S_SCOPECNT];258259/* number of times that each rule of source selection is applied. */260uint64_t ip6s_sources_rule[IP6S_RULESMAX];261};262263#ifdef _KERNEL264#include <sys/counter.h>265#include <netinet/in_kdtrace.h>266267VNET_PCPUSTAT_DECLARE(struct ip6stat, ip6stat);268#define IP6STAT_ADD(name, val) \269do { \270MIB_SDT_PROBE1(ip6, count, name, (val)); \271VNET_PCPUSTAT_ADD(struct ip6stat, ip6stat, name, (val)); \272} while (0)273#define IP6STAT_SUB(name, val) IP6STAT_ADD(name, -(val))274#define IP6STAT_INC(name) IP6STAT_ADD(name, 1)275#define IP6STAT_INC2(name, type) \276do { \277MIB_SDT_PROBE2(ip6, count, name, 1, type); \278VNET_PCPUSTAT_ADD(struct ip6stat, ip6stat, name, 1); \279} while (0)280#define IP6STAT_DEC(name) IP6STAT_SUB(name, 1)281#endif282283#ifdef _KERNEL284/* flags passed to ip6_output as last parameter */285#define IPV6_UNSPECSRC 0x01 /* allow :: as the source address */286#define IPV6_FORWARDING 0x02 /* most of IPv6 header exists */287#define IPV6_MINMTU 0x04 /* use minimum MTU (IPV6_USE_MIN_MTU) */288289#ifdef __NO_STRICT_ALIGNMENT290#define IP6_HDR_ALIGNED_P(ip) 1291#else292#define IP6_HDR_ALIGNED_P(ip) ((((intptr_t) (ip)) & 3) == 0)293#endif294295VNET_DECLARE(int, ip6_defhlim); /* default hop limit */296VNET_DECLARE(int, ip6_defmcasthlim); /* default multicast hop limit */297VNET_DECLARE(int, ip6_forwarding); /* act as router? */298VNET_DECLARE(int, ip6_use_deprecated); /* allow deprecated addr as source */299VNET_DECLARE(int, ip6_rr_prune); /* router renumbering prefix300* walk list every 5 sec. */301VNET_DECLARE(int, ip6_mcast_pmtu); /* enable pMTU discovery for multicast? */302VNET_DECLARE(int, ip6_v6only);303#define V_ip6_defhlim VNET(ip6_defhlim)304#define V_ip6_defmcasthlim VNET(ip6_defmcasthlim)305#define V_ip6_forwarding VNET(ip6_forwarding)306#define V_ip6_use_deprecated VNET(ip6_use_deprecated)307#define V_ip6_rr_prune VNET(ip6_rr_prune)308#define V_ip6_mcast_pmtu VNET(ip6_mcast_pmtu)309#define V_ip6_v6only VNET(ip6_v6only)310311VNET_DECLARE(struct socket *, ip6_mrouter); /* multicast routing daemon */312VNET_DECLARE(int, ip6_sendredirects); /* send IP redirects when forwarding? */313VNET_DECLARE(int, ip6_accept_rtadv); /* Acts as a host not a router */314VNET_DECLARE(int, ip6_no_radr); /* No defroute from RA */315VNET_DECLARE(int, ip6_norbit_raif); /* Disable R-bit in NA on RA316* receiving IF. */317VNET_DECLARE(int, ip6_rfc6204w3); /* Accept defroute from RA even when318forwarding enabled */319VNET_DECLARE(int, ip6_hdrnestlimit); /* upper limit of # of extension320* headers */321VNET_DECLARE(int, ip6_dad_count); /* DupAddrDetectionTransmits */322#define V_ip6_mrouter VNET(ip6_mrouter)323#define V_ip6_sendredirects VNET(ip6_sendredirects)324#define V_ip6_accept_rtadv VNET(ip6_accept_rtadv)325#define V_ip6_no_radr VNET(ip6_no_radr)326#define V_ip6_norbit_raif VNET(ip6_norbit_raif)327#define V_ip6_rfc6204w3 VNET(ip6_rfc6204w3)328#define V_ip6_hdrnestlimit VNET(ip6_hdrnestlimit)329#define V_ip6_dad_count VNET(ip6_dad_count)330331VNET_DECLARE(int, ip6_auto_flowlabel);332VNET_DECLARE(int, ip6_auto_linklocal);333#define V_ip6_auto_flowlabel VNET(ip6_auto_flowlabel)334#define V_ip6_auto_linklocal VNET(ip6_auto_linklocal)335336VNET_DECLARE(int, ip6_use_tempaddr); /* Whether to use temporary addresses */337VNET_DECLARE(int, ip6_prefer_tempaddr); /* Whether to prefer temporary338* addresses in the source address339* selection */340VNET_DECLARE(bool, ip6_use_stableaddr); /* Whether to use stable address generation (RFC 7217) */341#define V_ip6_use_tempaddr VNET(ip6_use_tempaddr)342#define V_ip6_prefer_tempaddr VNET(ip6_prefer_tempaddr)343#define V_ip6_use_stableaddr VNET(ip6_use_stableaddr)344345#define IP6_IDGEN_RETRIES 3 /* RFC 7217 section 7 default max retries */346VNET_DECLARE(u_int, ip6_stableaddr_maxretries);347#define V_ip6_stableaddr_maxretries VNET(ip6_stableaddr_maxretries)348349#define IP6_STABLEADDR_NETIFSRC_NAME 0350#define IP6_STABLEADDR_NETIFSRC_ID 1351#define IP6_STABLEADDR_NETIFSRC_MAC 2352VNET_DECLARE(int, ip6_stableaddr_netifsource);353#define V_ip6_stableaddr_netifsource VNET(ip6_stableaddr_netifsource)354355VNET_DECLARE(int, ip6_use_defzone); /* Whether to use the default scope356* zone when unspecified */357#define V_ip6_use_defzone VNET(ip6_use_defzone)358359VNET_DECLARE(struct pfil_head *, inet6_pfil_head);360#define V_inet6_pfil_head VNET(inet6_pfil_head)361#define PFIL_INET6_NAME "inet6"362363VNET_DECLARE(struct pfil_head *, inet6_local_pfil_head);364#define V_inet6_local_pfil_head VNET(inet6_local_pfil_head)365#define PFIL_INET6_LOCAL_NAME "inet6-local"366367#ifdef IPSTEALTH368VNET_DECLARE(int, ip6stealth);369#define V_ip6stealth VNET(ip6stealth)370#endif371372VNET_DECLARE(bool, ip6_log_cannot_forward);373#define V_ip6_log_cannot_forward VNET(ip6_log_cannot_forward)374375extern struct pr_usrreqs rip6_usrreqs;376struct sockopt;377378struct inpcb;379struct ucred;380381int icmp6_ctloutput(struct socket *, struct sockopt *sopt);382383void ip6_input(struct mbuf *);384void ip6_direct_input(struct mbuf *);385void ip6_freepcbopts(struct ip6_pktopts *);386387int ip6_unknown_opt(u_int8_t *, struct mbuf *, int);388int ip6_get_prevhdr(const struct mbuf *, int);389int ip6_nexthdr(const struct mbuf *, int, int, int *);390int ip6_lasthdr(const struct mbuf *, int, int, int *);391392extern int (*ip6_mforward)(struct ip6_hdr *, struct ifnet *,393struct mbuf *);394395int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,396u_int32_t *);397struct mbuf **ip6_savecontrol_v4(struct inpcb *, struct mbuf *,398struct mbuf **, int *);399void ip6_savecontrol(struct inpcb *, struct mbuf *, struct mbuf **);400void ip6_notify_pmtu(struct inpcb *, struct sockaddr_in6 *, u_int32_t);401int ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);402403void ip6_forward(struct mbuf *, int);404405void ip6_mloopback(struct ifnet *, struct mbuf *);406int ip6_output(struct mbuf *, struct ip6_pktopts *,407struct route_in6 *,408int,409struct ip6_moptions *, struct ifnet **,410struct inpcb *);411int ip6_ctloutput(struct socket *, struct sockopt *);412int ip6_raw_ctloutput(struct socket *, struct sockopt *);413void ip6_initpktopts(struct ip6_pktopts *);414int ip6_setpktopts(struct mbuf *, struct ip6_pktopts *,415struct ip6_pktopts *, struct ucred *, int);416void ip6_clearpktopts(struct ip6_pktopts *, int);417struct ip6_pktopts *ip6_copypktopts(struct ip6_pktopts *, int);418int ip6_optlen(struct inpcb *);419int ip6_deletefraghdr(struct mbuf *, int, int);420int ip6_fragment(struct ifnet *, struct mbuf *, int, u_char, int,421uint32_t);422423int route6_input(struct mbuf **, int *, int);424425void frag6_init(void);426void frag6_destroy(void);427int frag6_input(struct mbuf **, int *, int);428void frag6_drain(void *, int);429430void rip6_init(void);431int rip6_ctloutput(struct socket *, struct sockopt *);432int rip6_usrreq(struct socket *,433int, struct mbuf *, struct mbuf *, struct mbuf *, struct thread *);434435int dest6_input(struct mbuf **, int *, int);436int none_input(struct mbuf **, int *, int);437438int in6_selectsrc_socket(struct sockaddr_in6 *, struct ip6_pktopts *,439struct inpcb *, struct ucred *, int, struct in6_addr *, int *);440int in6_selectsrc_addr(uint32_t, const struct in6_addr *,441uint32_t, struct ifnet *, struct in6_addr *, int *);442int in6_selectsrc_nbr(uint32_t, const struct in6_addr *,443struct ip6_moptions *, struct ifnet *, struct in6_addr *);444int in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,445struct ip6_moptions *, struct route_in6 *, struct ifnet **,446struct nhop_object **, u_int, uint32_t);447u_int32_t ip6_randomid(void);448u_int32_t ip6_randomflowlabel(void);449void in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset);450451int ip6_log_ratelimit(void);452453/*454* Argument type for the last arg of ip6proto_ctlinput_t().455*456* IPv6 ICMP IPv6 [exthdrs] finalhdr payload457* ^ ^ ^ ^458* | | ip6c_ip6 ip6c_off459* | ip6c_icmp6460* ip6c_m461*462* ip6c_finaldst's sin6_addr usually points to ip6c_ip6->ip6_dst. If the463* original * (internal) packet carries a routing header, it may point the464* final * destination address in the routing header.465*466* ip6c_src: ip6c_ip6->ip6_src + scope info + flowlabel in ip6c_ip6467* (beware of flowlabel, if you try to compare it against others)468* ip6c_dst: ip6c_finaldst + scope info469*/470struct ip6ctlparam {471struct mbuf *ip6c_m; /* start of mbuf chain */472struct icmp6_hdr *ip6c_icmp6; /* icmp6 header of target packet */473struct ip6_hdr *ip6c_ip6; /* ip6 header of target packet */474int ip6c_off; /* offset of the target proto header */475struct sockaddr_in6 *ip6c_src; /* srcaddr w/ additional info */476struct sockaddr_in6 *ip6c_dst; /* (final) dstaddr w/ additional info */477struct sockaddr_in6 *ip6c_finaldst; /* final destination address */478void *ip6c_cmdarg; /* control command dependent data */479u_int8_t ip6c_nxt; /* final next header field */480};481482typedef int ip6proto_input_t(struct mbuf **, int *, int);483typedef void ip6proto_ctlinput_t(struct ip6ctlparam *);484int ip6proto_register(uint8_t, ip6proto_input_t, ip6proto_ctlinput_t);485int ip6proto_unregister(uint8_t);486#define IP6PROTO_REGISTER(prot, input, ctl) do { \487int error __diagused; \488error = ip6proto_register(prot, input, ctl); \489MPASS(error == 0); \490} while (0)491492ip6proto_input_t rip6_input;493ip6proto_ctlinput_t rip6_ctlinput;494495#endif /* _KERNEL */496497#endif /* !_NETINET6_IP6_VAR_H_ */498499500