File: | netinet6/ip6_output.c |
Warning: | line 2419, column 10 Copies out a struct with untouched element(s): ipi6_ifindex |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /*- | |||
2 | * SPDX-License-Identifier: BSD-3-Clause | |||
3 | * | |||
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |||
5 | * All rights reserved. | |||
6 | * | |||
7 | * Redistribution and use in source and binary forms, with or without | |||
8 | * modification, are permitted provided that the following conditions | |||
9 | * are met: | |||
10 | * 1. Redistributions of source code must retain the above copyright | |||
11 | * notice, this list of conditions and the following disclaimer. | |||
12 | * 2. Redistributions in binary form must reproduce the above copyright | |||
13 | * notice, this list of conditions and the following disclaimer in the | |||
14 | * documentation and/or other materials provided with the distribution. | |||
15 | * 3. Neither the name of the project nor the names of its contributors | |||
16 | * may be used to endorse or promote products derived from this software | |||
17 | * without specific prior written permission. | |||
18 | * | |||
19 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | |||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |||
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
29 | * SUCH DAMAGE. | |||
30 | * | |||
31 | * $KAME: ip6_output.c,v 1.279 2002/01/26 06:12:30 jinmei Exp $ | |||
32 | */ | |||
33 | ||||
34 | /*- | |||
35 | * Copyright (c) 1982, 1986, 1988, 1990, 1993 | |||
36 | * The Regents of the University of California. All rights reserved. | |||
37 | * | |||
38 | * Redistribution and use in source and binary forms, with or without | |||
39 | * modification, are permitted provided that the following conditions | |||
40 | * are met: | |||
41 | * 1. Redistributions of source code must retain the above copyright | |||
42 | * notice, this list of conditions and the following disclaimer. | |||
43 | * 2. Redistributions in binary form must reproduce the above copyright | |||
44 | * notice, this list of conditions and the following disclaimer in the | |||
45 | * documentation and/or other materials provided with the distribution. | |||
46 | * 3. Neither the name of the University nor the names of its contributors | |||
47 | * may be used to endorse or promote products derived from this software | |||
48 | * without specific prior written permission. | |||
49 | * | |||
50 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |||
51 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
53 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |||
54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||
56 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||
57 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||
58 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
59 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
60 | * SUCH DAMAGE. | |||
61 | * | |||
62 | * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 | |||
63 | */ | |||
64 | ||||
65 | #include <sys/cdefs.h> | |||
66 | __FBSDID("$FreeBSD$")__asm__(".ident\t\"" "$FreeBSD$" "\""); | |||
67 | ||||
68 | #include "opt_inet.h" | |||
69 | #include "opt_inet6.h" | |||
70 | #include "opt_ratelimit.h" | |||
71 | #include "opt_ipsec.h" | |||
72 | #include "opt_sctp.h" | |||
73 | #include "opt_route.h" | |||
74 | #include "opt_rss.h" | |||
75 | ||||
76 | #include <sys/param.h> | |||
77 | #include <sys/kernel.h> | |||
78 | #include <sys/malloc.h> | |||
79 | #include <sys/mbuf.h> | |||
80 | #include <sys/errno.h> | |||
81 | #include <sys/priv.h> | |||
82 | #include <sys/proc.h> | |||
83 | #include <sys/protosw.h> | |||
84 | #include <sys/socket.h> | |||
85 | #include <sys/socketvar.h> | |||
86 | #include <sys/syslog.h> | |||
87 | #include <sys/ucred.h> | |||
88 | ||||
89 | #include <machine/in_cksum.h> | |||
90 | ||||
91 | #include <net/if.h> | |||
92 | #include <net/if_var.h> | |||
93 | #include <net/if_llatbl.h> | |||
94 | #include <net/netisr.h> | |||
95 | #include <net/route.h> | |||
96 | #include <net/pfil.h> | |||
97 | #include <net/rss_config.h> | |||
98 | #include <net/vnet.h> | |||
99 | ||||
100 | #include <netinet/in.h> | |||
101 | #include <netinet/in_var.h> | |||
102 | #include <netinet/ip_var.h> | |||
103 | #include <netinet6/in6_fib.h> | |||
104 | #include <netinet6/in6_var.h> | |||
105 | #include <netinet/ip6.h> | |||
106 | #include <netinet/icmp6.h> | |||
107 | #include <netinet6/ip6_var.h> | |||
108 | #include <netinet/in_pcb.h> | |||
109 | #include <netinet/tcp_var.h> | |||
110 | #include <netinet6/nd6.h> | |||
111 | #include <netinet6/in6_rss.h> | |||
112 | ||||
113 | #include <netipsec/ipsec_support.h> | |||
114 | #ifdef SCTP1 | |||
115 | #include <netinet/sctp.h> | |||
116 | #include <netinet/sctp_crc32.h> | |||
117 | #endif | |||
118 | ||||
119 | #include <netinet6/ip6protosw.h> | |||
120 | #include <netinet6/scope6_var.h> | |||
121 | ||||
122 | extern int in6_mcast_loop; | |||
123 | ||||
124 | struct ip6_exthdrs { | |||
125 | struct mbuf *ip6e_ip6; | |||
126 | struct mbuf *ip6e_hbh; | |||
127 | struct mbuf *ip6e_dest1; | |||
128 | struct mbuf *ip6e_rthdr; | |||
129 | struct mbuf *ip6e_dest2; | |||
130 | }; | |||
131 | ||||
132 | static MALLOC_DEFINE(M_IP6OPT, "ip6opt", "IPv6 options")struct malloc_type M_IP6OPT[1] = { { ((void *)0), 877983977, "ip6opt" , ((void *)0) } }; static struct sysinit M_IP6OPT_init_sys_init = { SI_SUB_KMEM, SI_ORDER_THIRD, (sysinit_cfunc_t)(sysinit_nfunc_t )malloc_init, ((void *)(M_IP6OPT)) }; __asm__(".globl " "__start_set_sysinit_set" ); __asm__(".globl " "__stop_set_sysinit_set"); static void const * __set_sysinit_set_sym_M_IP6OPT_init_sys_init __attribute__ ((__section__("set_" "sysinit_set"))) __attribute__((__used__ )) = &(M_IP6OPT_init_sys_init); static struct sysinit M_IP6OPT_uninit_sys_uninit = { SI_SUB_KMEM, SI_ORDER_ANY, (sysinit_cfunc_t)(sysinit_nfunc_t )malloc_uninit, ((void *)(M_IP6OPT)) }; __asm__(".globl " "__start_set_sysuninit_set" ); __asm__(".globl " "__stop_set_sysuninit_set"); static void const * __set_sysuninit_set_sym_M_IP6OPT_uninit_sys_uninit __attribute__ ((__section__("set_" "sysuninit_set"))) __attribute__((__used__ )) = &(M_IP6OPT_uninit_sys_uninit); | |||
133 | ||||
134 | static int ip6_pcbopt(int, u_char *, int, struct ip6_pktopts **, | |||
135 | struct ucred *, int); | |||
136 | static int ip6_pcbopts(struct ip6_pktopts **, struct mbuf *, | |||
137 | struct socket *, struct sockopt *); | |||
138 | static int ip6_getpcbopt(struct inpcb *, int, struct sockopt *); | |||
139 | static int ip6_setpktopt(int, u_char *, int, struct ip6_pktopts *, | |||
140 | struct ucred *, int, int, int); | |||
141 | ||||
142 | static int ip6_copyexthdr(struct mbuf **, caddr_t, int); | |||
143 | static int ip6_insertfraghdr(struct mbuf *, struct mbuf *, int, | |||
144 | struct ip6_frag **); | |||
145 | static int ip6_insert_jumboopt(struct ip6_exthdrs *, u_int32_t); | |||
146 | static int ip6_splithdr(struct mbuf *, struct ip6_exthdrs *); | |||
147 | static int ip6_getpmtu(struct route_in6 *, int, | |||
148 | struct ifnet *, const struct in6_addr *, u_long *, int *, u_int, | |||
149 | u_int); | |||
150 | static int ip6_calcmtu(struct ifnet *, const struct in6_addr *, u_long, | |||
151 | u_long *, int *, u_int); | |||
152 | static int ip6_getpmtu_ctl(u_int, const struct in6_addr *, u_long *); | |||
153 | static int copypktopts(struct ip6_pktopts *, struct ip6_pktopts *, int); | |||
154 | ||||
155 | ||||
156 | /* | |||
157 | * Make an extension header from option data. hp is the source, and | |||
158 | * mp is the destination. | |||
159 | */ | |||
160 | #define MAKE_EXTHDR(hp, mp)do { if (hp) { struct ip6_ext *eh = (struct ip6_ext *)(hp); error = ip6_copyexthdr((mp), (caddr_t)(hp), ((eh)->ip6e_len + 1 ) << 3); if (error) goto freehdrs; } } while ( 0) \ | |||
161 | do { \ | |||
162 | if (hp) { \ | |||
163 | struct ip6_ext *eh = (struct ip6_ext *)(hp); \ | |||
164 | error = ip6_copyexthdr((mp), (caddr_t)(hp), \ | |||
165 | ((eh)->ip6e_len + 1) << 3); \ | |||
166 | if (error) \ | |||
167 | goto freehdrs; \ | |||
168 | } \ | |||
169 | } while (/*CONSTCOND*/ 0) | |||
170 | ||||
171 | /* | |||
172 | * Form a chain of extension headers. | |||
173 | * m is the extension header mbuf | |||
174 | * mp is the previous mbuf in the chain | |||
175 | * p is the next header | |||
176 | * i is the type of option. | |||
177 | */ | |||
178 | #define MAKE_CHAIN(m, mp, p, i)do { if (m) { if (!hdrsplit) panic("assumption failed: hdr not split" ); *((u_char *)(((m))->m_data)) = *(p); *(p) = (i); p = (( u_char *)(((m))->m_data)); (m)->m_next = (mp)->m_next ; (mp)->m_next = (m); (mp) = (m); } } while ( 0)\ | |||
179 | do {\ | |||
180 | if (m) {\ | |||
181 | if (!hdrsplit) \ | |||
182 | panic("assumption failed: hdr not split"); \ | |||
183 | *mtod((m), u_char *)((u_char *)(((m))->m_data)) = *(p);\ | |||
184 | *(p) = (i);\ | |||
185 | p = mtod((m), u_char *)((u_char *)(((m))->m_data));\ | |||
186 | (m)->m_next = (mp)->m_next;\ | |||
187 | (mp)->m_next = (m);\ | |||
188 | (mp) = (m);\ | |||
189 | }\ | |||
190 | } while (/*CONSTCOND*/ 0) | |||
191 | ||||
192 | void | |||
193 | in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset) | |||
194 | { | |||
195 | u_short csum; | |||
196 | ||||
197 | csum = in_cksum_skip(m, offset + plen, offset); | |||
198 | if (m->m_pkthdr.csum_flags & CSUM_UDP_IPV60x00000200 && csum == 0) | |||
199 | csum = 0xffff; | |||
200 | offset += m->m_pkthdr.csum_dataPH_per.thirtytwo[1]; /* checksum offset */ | |||
201 | ||||
202 | if (offset + sizeof(csum) > m->m_len) | |||
203 | m_copyback(m, offset, sizeof(csum), (caddr_t)&csum); | |||
204 | else | |||
205 | *(u_short *)mtodo(m, offset)((void *)(((m)->m_data) + (offset))) = csum; | |||
206 | } | |||
207 | ||||
208 | int | |||
209 | ip6_fragment(struct ifnet *ifp, struct mbuf *m0, int hlen, u_char nextproto, | |||
210 | int fraglen , uint32_t id) | |||
211 | { | |||
212 | struct mbuf *m, **mnext, *m_frgpart; | |||
213 | struct ip6_hdr *ip6, *mhip6; | |||
214 | struct ip6_frag *ip6f; | |||
215 | int off; | |||
216 | int error; | |||
217 | int tlen = m0->m_pkthdr.len; | |||
218 | ||||
219 | KASSERT((fraglen % 8 == 0), ("Fragment length must be a multiple of 8"))do { if (__builtin_expect((!((fraglen % 8 == 0))), 0)) panic ( "Fragment length must be a multiple of 8"); } while (0); | |||
220 | ||||
221 | m = m0; | |||
222 | ip6 = mtod(m, struct ip6_hdr *)((struct ip6_hdr *)((m)->m_data)); | |||
223 | mnext = &m->m_nextpkt; | |||
224 | ||||
225 | for (off = hlen; off < tlen; off += fraglen) { | |||
226 | m = m_gethdr(M_NOWAIT0x0001, MT_DATA1); | |||
227 | if (!m) { | |||
228 | IP6STAT_INC(ip6s_odropped)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_odropped) / sizeof (uint64_t)], ((1))); | |||
229 | return (ENOBUFS55); | |||
230 | } | |||
231 | m->m_flags = m0->m_flags & M_COPYFLAGS(0x00000002|0x00000004|0x00000008|0x00000010|0x00000020|0x00000040 |0x00000080|0x00000400| 0x00000800|(0x00001000|0x00002000|0x00004000 |0x00008000|0x00010000|0x00020000|0x00040000|0x00080000| 0x00100000 |0x00200000|0x00400000|0x00800000)); | |||
232 | *mnext = m; | |||
233 | mnext = &m->m_nextpkt; | |||
234 | m->m_data += max_linkhdr; | |||
235 | mhip6 = mtod(m, struct ip6_hdr *)((struct ip6_hdr *)((m)->m_data)); | |||
236 | *mhip6 = *ip6; | |||
237 | m->m_len = sizeof(*mhip6); | |||
238 | error = ip6_insertfraghdr(m0, m, hlen, &ip6f); | |||
239 | if (error) { | |||
240 | IP6STAT_INC(ip6s_odropped)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_odropped) / sizeof (uint64_t)], ((1))); | |||
241 | return (error); | |||
242 | } | |||
243 | ip6f->ip6f_offlg = htons((u_short)((off - hlen) & ~7))((__uint16_t)(__builtin_constant_p((u_short)((off - hlen) & ~7)) ? (__uint16_t)(((__uint16_t)((u_short)((off - hlen) & ~7))) << 8 | ((__uint16_t)((u_short)((off - hlen) & ~7))) >> 8) : __bswap16_var((u_short)((off - hlen) & ~7)))); | |||
244 | if (off + fraglen >= tlen) | |||
245 | fraglen = tlen - off; | |||
246 | else | |||
247 | ip6f->ip6f_offlg |= IP6F_MORE_FRAG0x0100; | |||
248 | mhip6->ip6_plenip6_ctlun.ip6_un1.ip6_un1_plen = htons((u_short)(fraglen + hlen +((__uint16_t)(__builtin_constant_p((u_short)(fraglen + hlen + sizeof(*ip6f) - sizeof(struct ip6_hdr))) ? (__uint16_t)(((__uint16_t )((u_short)(fraglen + hlen + sizeof(*ip6f) - sizeof(struct ip6_hdr )))) << 8 | ((__uint16_t)((u_short)(fraglen + hlen + sizeof (*ip6f) - sizeof(struct ip6_hdr)))) >> 8) : __bswap16_var ((u_short)(fraglen + hlen + sizeof(*ip6f) - sizeof(struct ip6_hdr ))))) | |||
249 | sizeof(*ip6f) - sizeof(struct ip6_hdr)))((__uint16_t)(__builtin_constant_p((u_short)(fraglen + hlen + sizeof(*ip6f) - sizeof(struct ip6_hdr))) ? (__uint16_t)(((__uint16_t )((u_short)(fraglen + hlen + sizeof(*ip6f) - sizeof(struct ip6_hdr )))) << 8 | ((__uint16_t)((u_short)(fraglen + hlen + sizeof (*ip6f) - sizeof(struct ip6_hdr)))) >> 8) : __bswap16_var ((u_short)(fraglen + hlen + sizeof(*ip6f) - sizeof(struct ip6_hdr ))))); | |||
250 | if ((m_frgpart = m_copym(m0, off, fraglen, M_NOWAIT0x0001)) == NULL((void *)0)) { | |||
251 | IP6STAT_INC(ip6s_odropped)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_odropped) / sizeof (uint64_t)], ((1))); | |||
252 | return (ENOBUFS55); | |||
253 | } | |||
254 | m_cat(m, m_frgpart); | |||
255 | m->m_pkthdr.len = fraglen + hlen + sizeof(*ip6f); | |||
256 | m->m_pkthdr.fibnum = m0->m_pkthdr.fibnum; | |||
257 | m->m_pkthdr.rcvif = NULL((void *)0); | |||
258 | ip6f->ip6f_reserved = 0; | |||
259 | ip6f->ip6f_ident = id; | |||
260 | ip6f->ip6f_nxt = nextproto; | |||
261 | IP6STAT_INC(ip6s_ofragments)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_ofragments) / sizeof (uint64_t)], ((1))); | |||
262 | in6_ifstat_inc(ifp, ifs6_out_fragcreat)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_fragcreat) / sizeof(uint64_t)], 1);} while ( 0); | |||
263 | } | |||
264 | ||||
265 | return (0); | |||
266 | } | |||
267 | ||||
268 | /* | |||
269 | * IP6 output. The packet in mbuf chain m contains a skeletal IP6 | |||
270 | * header (with pri, len, nxt, hlim, src, dst). | |||
271 | * This function may modify ver and hlim only. | |||
272 | * The mbuf chain containing the packet will be freed. | |||
273 | * The mbuf opt, if present, will not be freed. | |||
274 | * If route_in6 ro is present and has ro_rt initialized, route lookup would be | |||
275 | * skipped and ro->ro_rt would be used. If ro is present but ro->ro_rt is NULL, | |||
276 | * then result of route lookup is stored in ro->ro_rt. | |||
277 | * | |||
278 | * type of "mtu": rt_mtu is u_long, ifnet.ifr_mtu is int, and | |||
279 | * nd_ifinfo.linkmtu is u_int32_t. so we use u_long to hold largest one, | |||
280 | * which is rt_mtu. | |||
281 | * | |||
282 | * ifpp - XXX: just for statistics | |||
283 | */ | |||
284 | /* | |||
285 | * XXX TODO: no flowid is assigned for outbound flows? | |||
286 | */ | |||
287 | int | |||
288 | ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, | |||
289 | struct route_in6 *ro, int flags, struct ip6_moptions *im6o, | |||
290 | struct ifnet **ifpp, struct inpcb *inp) | |||
291 | { | |||
292 | struct ip6_hdr *ip6; | |||
293 | struct ifnet *ifp, *origifp; | |||
294 | struct mbuf *m = m0; | |||
295 | struct mbuf *mprev = NULL((void *)0); | |||
296 | int hlen, tlen, len; | |||
297 | struct route_in6 ip6route; | |||
298 | struct rtentry *rt = NULL((void *)0); | |||
299 | struct sockaddr_in6 *dst, src_sa, dst_sa; | |||
300 | struct in6_addr odst; | |||
301 | int error = 0; | |||
302 | struct in6_ifaddr *ia = NULL((void *)0); | |||
303 | u_long mtu; | |||
304 | int alwaysfrag, dontfrag; | |||
305 | u_int32_t optlen = 0, plen = 0, unfragpartlen = 0; | |||
306 | struct ip6_exthdrs exthdrs; | |||
307 | struct in6_addr src0, dst0; | |||
308 | u_int32_t zone; | |||
309 | struct route_in6 *ro_pmtu = NULL((void *)0); | |||
310 | int hdrsplit = 0; | |||
311 | int sw_csum, tso; | |||
312 | int needfiblookup; | |||
313 | uint32_t fibnum; | |||
314 | struct m_tag *fwd_tag = NULL((void *)0); | |||
315 | uint32_t id; | |||
316 | ||||
317 | if (inp != NULL((void *)0)) { | |||
318 | INP_LOCK_ASSERT(inp)__rw_assert(&((&(inp)->inp_lock))->rw_lock, (0x00000001 ), "/root/freebsd/sys/netinet6/ip6_output.c", 318); | |||
319 | M_SETFIB(m, inp->inp_inc.inc_fibnum)do { do { if (__builtin_expect((!((m)->m_flags & 0x00000002 )), 0)) panic ("Attempt to set FIB on non header mbuf."); } while (0); ((m)->m_pkthdr.fibnum) = (inp->inp_inc.inc_fibnum ); } while (0); | |||
320 | if ((flags & IP_NODEFAULTFLOWID0x40) == 0) { | |||
321 | /* unconditionally set flowid */ | |||
322 | m->m_pkthdr.flowid = inp->inp_flowid; | |||
323 | M_HASHTYPE_SET(m, inp->inp_flowtype)((m)->m_pkthdr.rsstype = (inp->inp_flowtype)); | |||
324 | } | |||
325 | } | |||
326 | ||||
327 | #if defined(IPSEC1) || defined(IPSEC_SUPPORT1) | |||
328 | /* | |||
329 | * IPSec checking which handles several cases. | |||
330 | * FAST IPSEC: We re-injected the packet. | |||
331 | * XXX: need scope argument. | |||
332 | */ | |||
333 | if (IPSEC_ENABLED(ipv6)((ipv6_ipsec_support)->enabled & 0x0001)) { | |||
334 | if ((error = IPSEC_OUTPUT(ipv6, m, inp)(*(ipv6_ipsec_support)->methods->output)(m, inp)) != 0) { | |||
335 | if (error == EINPROGRESS36) | |||
336 | error = 0; | |||
337 | goto done; | |||
338 | } | |||
339 | } | |||
340 | #endif /* IPSEC */ | |||
341 | ||||
342 | bzero(&exthdrs, sizeof(exthdrs))__builtin_memset((&exthdrs), 0, (sizeof(exthdrs))); | |||
343 | if (opt) { | |||
344 | /* Hop-by-Hop options header */ | |||
345 | MAKE_EXTHDR(opt->ip6po_hbh, &exthdrs.ip6e_hbh)do { if (opt->ip6po_hbh) { struct ip6_ext *eh = (struct ip6_ext *)(opt->ip6po_hbh); error = ip6_copyexthdr((&exthdrs. ip6e_hbh), (caddr_t)(opt->ip6po_hbh), ((eh)->ip6e_len + 1) << 3); if (error) goto freehdrs; } } while ( 0); | |||
346 | /* Destination options header(1st part) */ | |||
347 | if (opt->ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr) { | |||
348 | /* | |||
349 | * Destination options header(1st part) | |||
350 | * This only makes sense with a routing header. | |||
351 | * See Section 9.2 of RFC 3542. | |||
352 | * Disabling this part just for MIP6 convenience is | |||
353 | * a bad idea. We need to think carefully about a | |||
354 | * way to make the advanced API coexist with MIP6 | |||
355 | * options, which might automatically be inserted in | |||
356 | * the kernel. | |||
357 | */ | |||
358 | MAKE_EXTHDR(opt->ip6po_dest1, &exthdrs.ip6e_dest1)do { if (opt->ip6po_dest1) { struct ip6_ext *eh = (struct ip6_ext *)(opt->ip6po_dest1); error = ip6_copyexthdr((&exthdrs .ip6e_dest1), (caddr_t)(opt->ip6po_dest1), ((eh)->ip6e_len + 1) << 3); if (error) goto freehdrs; } } while ( 0); | |||
359 | } | |||
360 | /* Routing header */ | |||
361 | MAKE_EXTHDR(opt->ip6po_rthdr, &exthdrs.ip6e_rthdr)do { if (opt->ip6po_rhinfo.ip6po_rhi_rthdr) { struct ip6_ext *eh = (struct ip6_ext *)(opt->ip6po_rhinfo.ip6po_rhi_rthdr ); error = ip6_copyexthdr((&exthdrs.ip6e_rthdr), (caddr_t )(opt->ip6po_rhinfo.ip6po_rhi_rthdr), ((eh)->ip6e_len + 1) << 3); if (error) goto freehdrs; } } while ( 0); | |||
362 | /* Destination options header(2nd part) */ | |||
363 | MAKE_EXTHDR(opt->ip6po_dest2, &exthdrs.ip6e_dest2)do { if (opt->ip6po_dest2) { struct ip6_ext *eh = (struct ip6_ext *)(opt->ip6po_dest2); error = ip6_copyexthdr((&exthdrs .ip6e_dest2), (caddr_t)(opt->ip6po_dest2), ((eh)->ip6e_len + 1) << 3); if (error) goto freehdrs; } } while ( 0); | |||
364 | } | |||
365 | ||||
366 | /* | |||
367 | * Calculate the total length of the extension header chain. | |||
368 | * Keep the length of the unfragmentable part for fragmentation. | |||
369 | */ | |||
370 | optlen = 0; | |||
371 | if (exthdrs.ip6e_hbh) | |||
372 | optlen += exthdrs.ip6e_hbh->m_len; | |||
373 | if (exthdrs.ip6e_dest1) | |||
374 | optlen += exthdrs.ip6e_dest1->m_len; | |||
375 | if (exthdrs.ip6e_rthdr) | |||
376 | optlen += exthdrs.ip6e_rthdr->m_len; | |||
377 | unfragpartlen = optlen + sizeof(struct ip6_hdr); | |||
378 | ||||
379 | /* NOTE: we don't add AH/ESP length here (done in ip6_ipsec_output) */ | |||
380 | if (exthdrs.ip6e_dest2) | |||
381 | optlen += exthdrs.ip6e_dest2->m_len; | |||
382 | ||||
383 | /* | |||
384 | * If there is at least one extension header, | |||
385 | * separate IP6 header from the payload. | |||
386 | */ | |||
387 | if (optlen && !hdrsplit) { | |||
388 | if ((error = ip6_splithdr(m, &exthdrs)) != 0) { | |||
389 | m = NULL((void *)0); | |||
390 | goto freehdrs; | |||
391 | } | |||
392 | m = exthdrs.ip6e_ip6; | |||
393 | hdrsplit++; | |||
394 | } | |||
395 | ||||
396 | ip6 = mtod(m, struct ip6_hdr *)((struct ip6_hdr *)((m)->m_data)); | |||
397 | ||||
398 | /* adjust mbuf packet header length */ | |||
399 | m->m_pkthdr.len += optlen; | |||
400 | plen = m->m_pkthdr.len - sizeof(*ip6); | |||
401 | ||||
402 | /* If this is a jumbo payload, insert a jumbo payload option. */ | |||
403 | if (plen > IPV6_MAXPACKET65535) { | |||
404 | if (!hdrsplit) { | |||
405 | if ((error = ip6_splithdr(m, &exthdrs)) != 0) { | |||
406 | m = NULL((void *)0); | |||
407 | goto freehdrs; | |||
408 | } | |||
409 | m = exthdrs.ip6e_ip6; | |||
410 | hdrsplit++; | |||
411 | } | |||
412 | /* adjust pointer */ | |||
413 | ip6 = mtod(m, struct ip6_hdr *)((struct ip6_hdr *)((m)->m_data)); | |||
414 | if ((error = ip6_insert_jumboopt(&exthdrs, plen)) != 0) | |||
415 | goto freehdrs; | |||
416 | ip6->ip6_plenip6_ctlun.ip6_un1.ip6_un1_plen = 0; | |||
417 | } else | |||
418 | ip6->ip6_plenip6_ctlun.ip6_un1.ip6_un1_plen = htons(plen)((__uint16_t)(__builtin_constant_p(plen) ? (__uint16_t)(((__uint16_t )(plen)) << 8 | ((__uint16_t)(plen)) >> 8) : __bswap16_var (plen))); | |||
419 | ||||
420 | /* | |||
421 | * Concatenate headers and fill in next header fields. | |||
422 | * Here we have, on "m" | |||
423 | * IPv6 payload | |||
424 | * and we insert headers accordingly. Finally, we should be getting: | |||
425 | * IPv6 hbh dest1 rthdr ah* [esp* dest2 payload] | |||
426 | * | |||
427 | * during the header composing process, "m" points to IPv6 header. | |||
428 | * "mprev" points to an extension header prior to esp. | |||
429 | */ | |||
430 | u_char *nexthdrp = &ip6->ip6_nxtip6_ctlun.ip6_un1.ip6_un1_nxt; | |||
431 | mprev = m; | |||
432 | ||||
433 | /* | |||
434 | * we treat dest2 specially. this makes IPsec processing | |||
435 | * much easier. the goal here is to make mprev point the | |||
436 | * mbuf prior to dest2. | |||
437 | * | |||
438 | * result: IPv6 dest2 payload | |||
439 | * m and mprev will point to IPv6 header. | |||
440 | */ | |||
441 | if (exthdrs.ip6e_dest2) { | |||
442 | if (!hdrsplit) | |||
443 | panic("assumption failed: hdr not split"); | |||
444 | exthdrs.ip6e_dest2->m_next = m->m_next; | |||
445 | m->m_next = exthdrs.ip6e_dest2; | |||
446 | *mtod(exthdrs.ip6e_dest2, u_char *)((u_char *)((exthdrs.ip6e_dest2)->m_data)) = ip6->ip6_nxtip6_ctlun.ip6_un1.ip6_un1_nxt; | |||
447 | ip6->ip6_nxtip6_ctlun.ip6_un1.ip6_un1_nxt = IPPROTO_DSTOPTS60; | |||
448 | } | |||
449 | ||||
450 | /* | |||
451 | * result: IPv6 hbh dest1 rthdr dest2 payload | |||
452 | * m will point to IPv6 header. mprev will point to the | |||
453 | * extension header prior to dest2 (rthdr in the above case). | |||
454 | */ | |||
455 | MAKE_CHAIN(exthdrs.ip6e_hbh, mprev, nexthdrp, IPPROTO_HOPOPTS)do { if (exthdrs.ip6e_hbh) { if (!hdrsplit) panic("assumption failed: hdr not split" ); *((u_char *)(((exthdrs.ip6e_hbh))->m_data)) = *(nexthdrp ); *(nexthdrp) = (0); nexthdrp = ((u_char *)(((exthdrs.ip6e_hbh ))->m_data)); (exthdrs.ip6e_hbh)->m_next = (mprev)-> m_next; (mprev)->m_next = (exthdrs.ip6e_hbh); (mprev) = (exthdrs .ip6e_hbh); } } while ( 0); | |||
456 | MAKE_CHAIN(exthdrs.ip6e_dest1, mprev, nexthdrp,do { if (exthdrs.ip6e_dest1) { if (!hdrsplit) panic("assumption failed: hdr not split" ); *((u_char *)(((exthdrs.ip6e_dest1))->m_data)) = *(nexthdrp ); *(nexthdrp) = (60); nexthdrp = ((u_char *)(((exthdrs.ip6e_dest1 ))->m_data)); (exthdrs.ip6e_dest1)->m_next = (mprev)-> m_next; (mprev)->m_next = (exthdrs.ip6e_dest1); (mprev) = ( exthdrs.ip6e_dest1); } } while ( 0) | |||
457 | IPPROTO_DSTOPTS)do { if (exthdrs.ip6e_dest1) { if (!hdrsplit) panic("assumption failed: hdr not split" ); *((u_char *)(((exthdrs.ip6e_dest1))->m_data)) = *(nexthdrp ); *(nexthdrp) = (60); nexthdrp = ((u_char *)(((exthdrs.ip6e_dest1 ))->m_data)); (exthdrs.ip6e_dest1)->m_next = (mprev)-> m_next; (mprev)->m_next = (exthdrs.ip6e_dest1); (mprev) = ( exthdrs.ip6e_dest1); } } while ( 0); | |||
458 | MAKE_CHAIN(exthdrs.ip6e_rthdr, mprev, nexthdrp,do { if (exthdrs.ip6e_rthdr) { if (!hdrsplit) panic("assumption failed: hdr not split" ); *((u_char *)(((exthdrs.ip6e_rthdr))->m_data)) = *(nexthdrp ); *(nexthdrp) = (43); nexthdrp = ((u_char *)(((exthdrs.ip6e_rthdr ))->m_data)); (exthdrs.ip6e_rthdr)->m_next = (mprev)-> m_next; (mprev)->m_next = (exthdrs.ip6e_rthdr); (mprev) = ( exthdrs.ip6e_rthdr); } } while ( 0) | |||
459 | IPPROTO_ROUTING)do { if (exthdrs.ip6e_rthdr) { if (!hdrsplit) panic("assumption failed: hdr not split" ); *((u_char *)(((exthdrs.ip6e_rthdr))->m_data)) = *(nexthdrp ); *(nexthdrp) = (43); nexthdrp = ((u_char *)(((exthdrs.ip6e_rthdr ))->m_data)); (exthdrs.ip6e_rthdr)->m_next = (mprev)-> m_next; (mprev)->m_next = (exthdrs.ip6e_rthdr); (mprev) = ( exthdrs.ip6e_rthdr); } } while ( 0); | |||
460 | ||||
461 | /* | |||
462 | * If there is a routing header, discard the packet. | |||
463 | */ | |||
464 | if (exthdrs.ip6e_rthdr) { | |||
465 | error = EINVAL22; | |||
466 | goto bad; | |||
467 | } | |||
468 | ||||
469 | /* Source address validation */ | |||
470 | if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)((&ip6->ip6_src)->__u6_addr.__u6_addr32[0] == 0 && (&ip6->ip6_src)->__u6_addr.__u6_addr32[1] == 0 && (&ip6->ip6_src)->__u6_addr.__u6_addr32[2] == 0 && (&ip6->ip6_src)->__u6_addr.__u6_addr32[3] == 0) && | |||
471 | (flags & IPV6_UNSPECSRC0x01) == 0) { | |||
472 | error = EOPNOTSUPP45; | |||
473 | IP6STAT_INC(ip6s_badscope)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_badscope) / sizeof (uint64_t)], ((1))); | |||
474 | goto bad; | |||
475 | } | |||
476 | if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_src)((&ip6->ip6_src)->__u6_addr.__u6_addr8[0] == 0xff)) { | |||
477 | error = EOPNOTSUPP45; | |||
478 | IP6STAT_INC(ip6s_badscope)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_badscope) / sizeof (uint64_t)], ((1))); | |||
479 | goto bad; | |||
480 | } | |||
481 | ||||
482 | IP6STAT_INC(ip6s_localout)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_localout) / sizeof (uint64_t)], ((1))); | |||
483 | ||||
484 | /* | |||
485 | * Route packet. | |||
486 | */ | |||
487 | if (ro == NULL((void *)0)) { | |||
488 | ro = &ip6route; | |||
489 | bzero((caddr_t)ro, sizeof(*ro))__builtin_memset(((caddr_t)ro), 0, (sizeof(*ro))); | |||
490 | } | |||
491 | ro_pmtu = ro; | |||
492 | if (opt && opt->ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr) | |||
493 | ro = &opt->ip6po_routeip6po_rhinfo.ip6po_rhi_route; | |||
494 | dst = (struct sockaddr_in6 *)&ro->ro_dst; | |||
495 | fibnum = (inp != NULL((void *)0)) ? inp->inp_inc.inc_fibnum : M_GETFIB(m)rt_m_getfib(m); | |||
496 | again: | |||
497 | /* | |||
498 | * if specified, try to fill in the traffic class field. | |||
499 | * do not override if a non-zero value is already set. | |||
500 | * we check the diffserv field and the ecn field separately. | |||
501 | */ | |||
502 | if (opt && opt->ip6po_tclass >= 0) { | |||
503 | int mask = 0; | |||
504 | ||||
505 | if ((ip6->ip6_flowip6_ctlun.ip6_un1.ip6_un1_flow & htonl(0xfc << 20)(__builtin_constant_p(0xfc << 20) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)(0xfc << 20)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(0xfc << 20)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t) (0xfc << 20)) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)(0xfc << 20)) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(0xfc << 20)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) (0xfc << 20)) >> 16)) << 8 | ((__uint16_t)( ((__uint32_t)(0xfc << 20)) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(0xfc << 20)) >> 16)))) : __bswap32_var (0xfc << 20))) == 0) | |||
506 | mask |= 0xfc; | |||
507 | if ((ip6->ip6_flowip6_ctlun.ip6_un1.ip6_un1_flow & htonl(0x03 << 20)(__builtin_constant_p(0x03 << 20) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)(0x03 << 20)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(0x03 << 20)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t) (0x03 << 20)) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)(0x03 << 20)) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(0x03 << 20)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) (0x03 << 20)) >> 16)) << 8 | ((__uint16_t)( ((__uint32_t)(0x03 << 20)) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(0x03 << 20)) >> 16)))) : __bswap32_var (0x03 << 20))) == 0) | |||
508 | mask |= 0x03; | |||
509 | if (mask != 0) | |||
510 | ip6->ip6_flowip6_ctlun.ip6_un1.ip6_un1_flow |= htonl((opt->ip6po_tclass & mask) << 20)(__builtin_constant_p((opt->ip6po_tclass & mask) << 20) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t )((opt->ip6po_tclass & mask) << 20)) & 0xffff ) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((opt->ip6po_tclass & mask) << 20)) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((opt->ip6po_tclass & mask) << 20 )) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(( opt->ip6po_tclass & mask) << 20)) & 0xffff)) ) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((opt->ip6po_tclass & mask) << 20)) >> 16 ) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((opt->ip6po_tclass & mask) << 20)) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)((opt->ip6po_tclass & mask) << 20 )) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((opt ->ip6po_tclass & mask) << 20)) >> 16)))) : __bswap32_var((opt->ip6po_tclass & mask) << 20) ); | |||
511 | } | |||
512 | ||||
513 | /* fill in or override the hop limit field, if necessary. */ | |||
514 | if (opt && opt->ip6po_hlim != -1) | |||
515 | ip6->ip6_hlimip6_ctlun.ip6_un1.ip6_un1_hlim = opt->ip6po_hlim & 0xff; | |||
516 | else if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)((&ip6->ip6_dst)->__u6_addr.__u6_addr8[0] == 0xff)) { | |||
517 | if (im6o != NULL((void *)0)) | |||
518 | ip6->ip6_hlimip6_ctlun.ip6_un1.ip6_un1_hlim = im6o->im6o_multicast_hlim; | |||
519 | else | |||
520 | ip6->ip6_hlimip6_ctlun.ip6_un1.ip6_un1_hlim = V_ip6_defmcasthlim(*(__typeof(vnet_entry_ip6_defmcasthlim)*) (((((__curthread() )->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6_defmcasthlim )); | |||
521 | } | |||
522 | /* | |||
523 | * Validate route against routing table additions; | |||
524 | * a better/more specific route might have been added. | |||
525 | * Make sure address family is set in route. | |||
526 | */ | |||
527 | if (inp) { | |||
528 | ro->ro_dst.sin6_family = AF_INET628; | |||
529 | RT_VALIDATE((struct route *)ro, &inp->inp_rt_cookie, fibnum)do { rt_gen_t cookie = rt_tables_get_gen(fibnum, ((struct route *)ro)->ro_dst.sa_family); if (*(&inp->inp_rt_cookie ) != cookie) { do { do { if (((struct route *)ro)->ro_rt) do { __mtx_lock_flags(&((((&(((struct route *)ro)->ro_rt )->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (529)); do { if ((((struct route *)ro)->ro_rt)->rt_refcnt <= 1) rtfree(((struct route *)ro)->ro_rt); else { do { __mtx_assert(&(((&(((struct route *)ro)->ro_rt)-> rt_mtx)))->mtx_lock, ((0x00000004)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (529)); do { if (__builtin_expect((!((((struct route *)ro) ->ro_rt)->rt_refcnt > 0)), 0)) panic ("bogus refcnt %d" , (((struct route *)ro)->ro_rt)->rt_refcnt); } while (0 ); (((struct route *)ro)->ro_rt)->rt_refcnt--; } while ( 0); __mtx_unlock_flags(&((((&(((struct route *)ro)-> ro_rt)->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (529)); } ((struct route *)ro)->ro_rt = 0; } while (0); } while (0); } while (0); if (((struct route *)ro)->ro_lle != ((void *)0)) { do { _rw_wlock_cookie(&((&(((struct route *)ro)->ro_lle)->lle_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 529); do { if ((((struct route *)ro)->ro_lle)->lle_refcnt == 1) (((struct route *)ro)->ro_lle)->lle_free(((struct route *)ro)->ro_lle); else { do { __rw_assert(&((& (((struct route *)ro)->ro_lle)->lle_lock))->rw_lock, (0x00000004), "/root/freebsd/sys/netinet6/ip6_output.c", 529 ); do { if (__builtin_expect((!((((struct route *)ro)->ro_lle )->lle_refcnt > 0)), 0)) panic ("bogus refcnt %d on lle %p" , (((struct route *)ro)->ro_lle)->lle_refcnt, (((struct route *)ro)->ro_lle)); } while (0); (((struct route *)ro) ->ro_lle)->lle_refcnt--; } while (0); _rw_wunlock_cookie (&((&(((struct route *)ro)->ro_lle)->lle_lock)) ->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 529) ; } (((struct route *)ro)->ro_lle) = ((void *)0); } while ( 0); } while (0); ((struct route *)ro)->ro_lle = ((void *)0 ); } } while (0); *(&inp->inp_rt_cookie) = cookie; } } while (0); | |||
530 | } | |||
531 | if (ro->ro_rt && fwd_tag == NULL((void *)0) && (ro->ro_rt->rt_flags & RTF_UP0x1) && | |||
532 | ro->ro_dst.sin6_family == AF_INET628 && | |||
533 | IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, &ip6->ip6_dst)(__builtin_memcmp((&(&ro->ro_dst.sin6_addr)->__u6_addr .__u6_addr8[0]), (&(&ip6->ip6_dst)->__u6_addr.__u6_addr8 [0]), (sizeof(struct in6_addr))) == 0)) { | |||
534 | rt = ro->ro_rt; | |||
535 | ifp = ro->ro_rt->rt_ifp; | |||
536 | } else { | |||
537 | if (ro->ro_lle) | |||
538 | LLE_FREE(ro->ro_lle)do { _rw_wlock_cookie(&((&(ro->ro_lle)->lle_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 538 ); do { if ((ro->ro_lle)->lle_refcnt == 1) (ro->ro_lle )->lle_free(ro->ro_lle); else { do { __rw_assert(&( (&(ro->ro_lle)->lle_lock))->rw_lock, (0x00000004 ), "/root/freebsd/sys/netinet6/ip6_output.c", 538); do { if ( __builtin_expect((!((ro->ro_lle)->lle_refcnt > 0)), 0 )) panic ("bogus refcnt %d on lle %p", (ro->ro_lle)->lle_refcnt , (ro->ro_lle)); } while (0); (ro->ro_lle)->lle_refcnt --; } while (0); _rw_wunlock_cookie(&((&(ro->ro_lle )->lle_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 538); } (ro->ro_lle) = ((void *)0); } while (0); } while (0); /* zeros ro_lle */ | |||
539 | ro->ro_lle = NULL((void *)0); | |||
540 | if (fwd_tag == NULL((void *)0)) { | |||
541 | bzero(&dst_sa, sizeof(dst_sa))__builtin_memset((&dst_sa), 0, (sizeof(dst_sa))); | |||
542 | dst_sa.sin6_family = AF_INET628; | |||
543 | dst_sa.sin6_len = sizeof(dst_sa); | |||
544 | dst_sa.sin6_addr = ip6->ip6_dst; | |||
545 | } | |||
546 | error = in6_selectroute_fib(&dst_sa, opt, im6o, ro, &ifp, | |||
547 | &rt, fibnum); | |||
548 | if (error != 0) { | |||
549 | if (ifp != NULL((void *)0)) | |||
550 | in6_ifstat_inc(ifp, ifs6_out_discard)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_discard) / sizeof(uint64_t)], 1);} while ( 0); | |||
551 | goto bad; | |||
552 | } | |||
553 | } | |||
554 | if (rt == NULL((void *)0)) { | |||
555 | /* | |||
556 | * If in6_selectroute() does not return a route entry, | |||
557 | * dst may not have been updated. | |||
558 | */ | |||
559 | *dst = dst_sa; /* XXX */ | |||
560 | } | |||
561 | ||||
562 | /* | |||
563 | * then rt (for unicast) and ifp must be non-NULL valid values. | |||
564 | */ | |||
565 | if ((flags & IPV6_FORWARDING0x02) == 0) { | |||
566 | /* XXX: the FORWARDING flag can be set for mrouting. */ | |||
567 | in6_ifstat_inc(ifp, ifs6_out_request)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_request) / sizeof(uint64_t)], 1);} while ( 0); | |||
568 | } | |||
569 | if (rt != NULL((void *)0)) { | |||
570 | ia = (struct in6_ifaddr *)(rt->rt_ifa); | |||
571 | counter_u64_add(rt->rt_pksent, 1); | |||
572 | } | |||
573 | ||||
574 | ||||
575 | /* | |||
576 | * The outgoing interface must be in the zone of source and | |||
577 | * destination addresses. | |||
578 | */ | |||
579 | origifp = ifp; | |||
580 | ||||
581 | src0 = ip6->ip6_src; | |||
582 | if (in6_setscope(&src0, origifp, &zone)) | |||
583 | goto badscope; | |||
584 | bzero(&src_sa, sizeof(src_sa))__builtin_memset((&src_sa), 0, (sizeof(src_sa))); | |||
585 | src_sa.sin6_family = AF_INET628; | |||
586 | src_sa.sin6_len = sizeof(src_sa); | |||
587 | src_sa.sin6_addr = ip6->ip6_src; | |||
588 | if (sa6_recoverscope(&src_sa) || zone != src_sa.sin6_scope_id) | |||
589 | goto badscope; | |||
590 | ||||
591 | dst0 = ip6->ip6_dst; | |||
592 | if (in6_setscope(&dst0, origifp, &zone)) | |||
593 | goto badscope; | |||
594 | /* re-initialize to be sure */ | |||
595 | bzero(&dst_sa, sizeof(dst_sa))__builtin_memset((&dst_sa), 0, (sizeof(dst_sa))); | |||
596 | dst_sa.sin6_family = AF_INET628; | |||
597 | dst_sa.sin6_len = sizeof(dst_sa); | |||
598 | dst_sa.sin6_addr = ip6->ip6_dst; | |||
599 | if (sa6_recoverscope(&dst_sa) || zone != dst_sa.sin6_scope_id) { | |||
600 | goto badscope; | |||
601 | } | |||
602 | ||||
603 | /* We should use ia_ifp to support the case of | |||
604 | * sending packets to an address of our own. | |||
605 | */ | |||
606 | if (ia != NULL((void *)0) && ia->ia_ifpia_ifa.ifa_ifp) | |||
607 | ifp = ia->ia_ifpia_ifa.ifa_ifp; | |||
608 | ||||
609 | /* scope check is done. */ | |||
610 | goto routefound; | |||
611 | ||||
612 | badscope: | |||
613 | IP6STAT_INC(ip6s_badscope)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_badscope) / sizeof (uint64_t)], ((1))); | |||
614 | in6_ifstat_inc(origifp, ifs6_out_discard)do { if (origifp) counter_u64_add(((struct in6_ifextra *) ((origifp )->if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat, ifs6_out_discard) / sizeof(uint64_t)], 1);} while ( 0); | |||
615 | if (error == 0) | |||
616 | error = EHOSTUNREACH65; /* XXX */ | |||
617 | goto bad; | |||
618 | ||||
619 | routefound: | |||
620 | if (rt && !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)((&ip6->ip6_dst)->__u6_addr.__u6_addr8[0] == 0xff)) { | |||
621 | if (opt && opt->ip6po_nextrouteip6po_nhinfo.ip6po_nhi_route.ro_rt) { | |||
622 | /* | |||
623 | * The nexthop is explicitly specified by the | |||
624 | * application. We assume the next hop is an IPv6 | |||
625 | * address. | |||
626 | */ | |||
627 | dst = (struct sockaddr_in6 *)opt->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop; | |||
628 | } | |||
629 | else if ((rt->rt_flags & RTF_GATEWAY0x2)) | |||
630 | dst = (struct sockaddr_in6 *)rt->rt_gateway; | |||
631 | } | |||
632 | ||||
633 | if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)((&ip6->ip6_dst)->__u6_addr.__u6_addr8[0] == 0xff)) { | |||
634 | m->m_flags &= ~(M_BCAST0x00000010 | M_MCAST0x00000020); /* just in case */ | |||
635 | } else { | |||
636 | m->m_flags = (m->m_flags & ~M_BCAST0x00000010) | M_MCAST0x00000020; | |||
637 | in6_ifstat_inc(ifp, ifs6_out_mcast)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_mcast) / sizeof(uint64_t)], 1);} while ( 0); | |||
638 | /* | |||
639 | * Confirm that the outgoing interface supports multicast. | |||
640 | */ | |||
641 | if (!(ifp->if_flags & IFF_MULTICAST0x8000)) { | |||
642 | IP6STAT_INC(ip6s_noroute)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_noroute) / sizeof( uint64_t)], ((1))); | |||
643 | in6_ifstat_inc(ifp, ifs6_out_discard)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_discard) / sizeof(uint64_t)], 1);} while ( 0); | |||
644 | error = ENETUNREACH51; | |||
645 | goto bad; | |||
646 | } | |||
647 | if ((im6o == NULL((void *)0) && in6_mcast_loop) || | |||
648 | (im6o && im6o->im6o_multicast_loop)) { | |||
649 | /* | |||
650 | * Loop back multicast datagram if not expressly | |||
651 | * forbidden to do so, even if we have not joined | |||
652 | * the address; protocols will filter it later, | |||
653 | * thus deferring a hash lookup and lock acquisition | |||
654 | * at the expense of an m_copym(). | |||
655 | */ | |||
656 | ip6_mloopback(ifp, m); | |||
657 | } else { | |||
658 | /* | |||
659 | * If we are acting as a multicast router, perform | |||
660 | * multicast forwarding as if the packet had just | |||
661 | * arrived on the interface to which we are about | |||
662 | * to send. The multicast forwarding function | |||
663 | * recursively calls this function, using the | |||
664 | * IPV6_FORWARDING flag to prevent infinite recursion. | |||
665 | * | |||
666 | * Multicasts that are looped back by ip6_mloopback(), | |||
667 | * above, will be forwarded by the ip6_input() routine, | |||
668 | * if necessary. | |||
669 | */ | |||
670 | if (V_ip6_mrouter(*(__typeof(vnet_entry_ip6_mrouter)*) (((((__curthread())-> td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6_mrouter )) && (flags & IPV6_FORWARDING0x02) == 0) { | |||
671 | /* | |||
672 | * XXX: ip6_mforward expects that rcvif is NULL | |||
673 | * when it is called from the originating path. | |||
674 | * However, it may not always be the case. | |||
675 | */ | |||
676 | m->m_pkthdr.rcvif = NULL((void *)0); | |||
677 | if (ip6_mforward(ip6, ifp, m) != 0) { | |||
678 | m_freem(m); | |||
679 | goto done; | |||
680 | } | |||
681 | } | |||
682 | } | |||
683 | /* | |||
684 | * Multicasts with a hoplimit of zero may be looped back, | |||
685 | * above, but must not be transmitted on a network. | |||
686 | * Also, multicasts addressed to the loopback interface | |||
687 | * are not sent -- the above call to ip6_mloopback() will | |||
688 | * loop back a copy if this host actually belongs to the | |||
689 | * destination group on the loopback interface. | |||
690 | */ | |||
691 | if (ip6->ip6_hlimip6_ctlun.ip6_un1.ip6_un1_hlim == 0 || (ifp->if_flags & IFF_LOOPBACK0x8) || | |||
692 | IN6_IS_ADDR_MC_INTFACELOCAL(&ip6->ip6_dst)(((&ip6->ip6_dst)->__u6_addr.__u6_addr8[0] == 0xff) && (((&ip6->ip6_dst)->__u6_addr.__u6_addr8 [1] & 0x0f) == 0x01))) { | |||
693 | m_freem(m); | |||
694 | goto done; | |||
695 | } | |||
696 | } | |||
697 | ||||
698 | /* | |||
699 | * Fill the outgoing inteface to tell the upper layer | |||
700 | * to increment per-interface statistics. | |||
701 | */ | |||
702 | if (ifpp) | |||
703 | *ifpp = ifp; | |||
704 | ||||
705 | /* Determine path MTU. */ | |||
706 | if ((error = ip6_getpmtu(ro_pmtu, ro != ro_pmtu, ifp, &ip6->ip6_dst, | |||
707 | &mtu, &alwaysfrag, fibnum, *nexthdrp)) != 0) | |||
708 | goto bad; | |||
709 | ||||
710 | /* | |||
711 | * The caller of this function may specify to use the minimum MTU | |||
712 | * in some cases. | |||
713 | * An advanced API option (IPV6_USE_MIN_MTU) can also override MTU | |||
714 | * setting. The logic is a bit complicated; by default, unicast | |||
715 | * packets will follow path MTU while multicast packets will be sent at | |||
716 | * the minimum MTU. If IP6PO_MINMTU_ALL is specified, all packets | |||
717 | * including unicast ones will be sent at the minimum MTU. Multicast | |||
718 | * packets will always be sent at the minimum MTU unless | |||
719 | * IP6PO_MINMTU_DISABLE is explicitly specified. | |||
720 | * See RFC 3542 for more details. | |||
721 | */ | |||
722 | if (mtu > IPV6_MMTU1280) { | |||
723 | if ((flags & IPV6_MINMTU0x04)) | |||
724 | mtu = IPV6_MMTU1280; | |||
725 | else if (opt && opt->ip6po_minmtu == IP6PO_MINMTU_ALL1) | |||
726 | mtu = IPV6_MMTU1280; | |||
727 | else if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)((&ip6->ip6_dst)->__u6_addr.__u6_addr8[0] == 0xff) && | |||
728 | (opt == NULL((void *)0) || | |||
729 | opt->ip6po_minmtu != IP6PO_MINMTU_DISABLE0)) { | |||
730 | mtu = IPV6_MMTU1280; | |||
731 | } | |||
732 | } | |||
733 | ||||
734 | /* | |||
735 | * clear embedded scope identifiers if necessary. | |||
736 | * in6_clearscope will touch the addresses only when necessary. | |||
737 | */ | |||
738 | in6_clearscope(&ip6->ip6_src); | |||
739 | in6_clearscope(&ip6->ip6_dst); | |||
740 | ||||
741 | /* | |||
742 | * If the outgoing packet contains a hop-by-hop options header, | |||
743 | * it must be examined and processed even by the source node. | |||
744 | * (RFC 2460, section 4.) | |||
745 | */ | |||
746 | if (exthdrs.ip6e_hbh) { | |||
747 | struct ip6_hbh *hbh = mtod(exthdrs.ip6e_hbh, struct ip6_hbh *)((struct ip6_hbh *)((exthdrs.ip6e_hbh)->m_data)); | |||
748 | u_int32_t dummy; /* XXX unused */ | |||
749 | u_int32_t plen = 0; /* XXX: ip6_process will check the value */ | |||
750 | ||||
751 | #ifdef DIAGNOSTIC | |||
752 | if ((hbh->ip6h_len + 1) << 3 > exthdrs.ip6e_hbh->m_len) | |||
753 | panic("ip6e_hbh is not contiguous"); | |||
754 | #endif | |||
755 | /* | |||
756 | * XXX: if we have to send an ICMPv6 error to the sender, | |||
757 | * we need the M_LOOP flag since icmp6_error() expects | |||
758 | * the IPv6 and the hop-by-hop options header are | |||
759 | * contiguous unless the flag is set. | |||
760 | */ | |||
761 | m->m_flags |= M_LOOP0x00020000; | |||
762 | m->m_pkthdr.rcvif = ifp; | |||
763 | if (ip6_process_hopopts(m, (u_int8_t *)(hbh + 1), | |||
764 | ((hbh->ip6h_len + 1) << 3) - sizeof(struct ip6_hbh), | |||
765 | &dummy, &plen) < 0) { | |||
766 | /* m was already freed at this point */ | |||
767 | error = EINVAL22;/* better error? */ | |||
768 | goto done; | |||
769 | } | |||
770 | m->m_flags &= ~M_LOOP0x00020000; /* XXX */ | |||
771 | m->m_pkthdr.rcvif = NULL((void *)0); | |||
772 | } | |||
773 | ||||
774 | /* Jump over all PFIL processing if hooks are not active. */ | |||
775 | if (!PFIL_HOOKED(&V_inet6_pfil_hook)((&(*(__typeof(vnet_entry_inet6_pfil_hook)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_inet6_pfil_hook )))->ph_nhooks > 0)) | |||
776 | goto passout; | |||
777 | ||||
778 | odst = ip6->ip6_dst; | |||
779 | /* Run through list of hooks for output packets. */ | |||
780 | error = pfil_run_hooks(&V_inet6_pfil_hook(*(__typeof(vnet_entry_inet6_pfil_hook)*) (((((__curthread()) ->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_inet6_pfil_hook )), &m, ifp, PFIL_OUT0x00000002, 0, inp); | |||
781 | if (error != 0 || m == NULL((void *)0)) | |||
782 | goto done; | |||
783 | /* adjust pointer */ | |||
784 | ip6 = mtod(m, struct ip6_hdr *)((struct ip6_hdr *)((m)->m_data)); | |||
785 | ||||
786 | needfiblookup = 0; | |||
787 | /* See if destination IP address was changed by packet filter. */ | |||
788 | if (!IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst)(__builtin_memcmp((&(&odst)->__u6_addr.__u6_addr8[ 0]), (&(&ip6->ip6_dst)->__u6_addr.__u6_addr8[0] ), (sizeof(struct in6_addr))) == 0)) { | |||
789 | m->m_flags |= M_SKIP_FIREWALL0x00004000; | |||
790 | /* If destination is now ourself drop to ip6_input(). */ | |||
791 | if (in6_localip(&ip6->ip6_dst)) { | |||
792 | m->m_flags |= M_FASTFWD_OURS0x00001000; | |||
793 | if (m->m_pkthdr.rcvif == NULL((void *)0)) | |||
794 | m->m_pkthdr.rcvif = V_loif(*(__typeof(vnet_entry_loif)*) (((((__curthread())->td_vnet ))->vnet_data_base) + (uintptr_t)&vnet_entry_loif)); | |||
795 | if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6(0x00000400|0x00000200)) { | |||
796 | m->m_pkthdr.csum_flags |= | |||
797 | CSUM_DATA_VALID_IPV60x08000000 | CSUM_PSEUDO_HDR0x04000000; | |||
798 | m->m_pkthdr.csum_dataPH_per.thirtytwo[1] = 0xffff; | |||
799 | } | |||
800 | #ifdef SCTP1 | |||
801 | if (m->m_pkthdr.csum_flags & CSUM_SCTP_IPV60x00000800) | |||
802 | m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID0x08000000; | |||
803 | #endif | |||
804 | error = netisr_queue(NETISR_IPV66, m); | |||
805 | goto done; | |||
806 | } else { | |||
807 | RO_INVALIDATE_CACHE(ro)do { do { if ((ro)->ro_rt) do { __mtx_lock_flags(&(((( &((ro)->ro_rt)->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (807)); do { if (((ro)->ro_rt)->rt_refcnt <= 1) rtfree ((ro)->ro_rt); else { do { __mtx_assert(&(((&((ro) ->ro_rt)->rt_mtx)))->mtx_lock, ((0x00000004)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (807)); do { if (__builtin_expect((!(((ro)->ro_rt)-> rt_refcnt > 0)), 0)) panic ("bogus refcnt %d", ((ro)->ro_rt )->rt_refcnt); } while (0); ((ro)->ro_rt)->rt_refcnt --; } while (0); __mtx_unlock_flags(&((((&((ro)->ro_rt )->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (807)); } (ro)->ro_rt = 0; } while (0); } while (0); } while (0); if ((ro)->ro_lle != ((void *)0)) { do { _rw_wlock_cookie (&((&((ro)->ro_lle)->lle_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 807); do { if (((ro)->ro_lle)->lle_refcnt == 1) ((ro) ->ro_lle)->lle_free((ro)->ro_lle); else { do { __rw_assert (&((&((ro)->ro_lle)->lle_lock))->rw_lock, (0x00000004 ), "/root/freebsd/sys/netinet6/ip6_output.c", 807); do { if ( __builtin_expect((!(((ro)->ro_lle)->lle_refcnt > 0)) , 0)) panic ("bogus refcnt %d on lle %p", ((ro)->ro_lle)-> lle_refcnt, ((ro)->ro_lle)); } while (0); ((ro)->ro_lle )->lle_refcnt--; } while (0); _rw_wunlock_cookie(&((& ((ro)->ro_lle)->lle_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 807); } ((ro)->ro_lle) = ((void *)0); } while (0); } while (0); (ro)->ro_lle = ((void *)0); } } while (0); | |||
808 | needfiblookup = 1; /* Redo the routing table lookup. */ | |||
809 | } | |||
810 | } | |||
811 | /* See if fib was changed by packet filter. */ | |||
812 | if (fibnum != M_GETFIB(m)rt_m_getfib(m)) { | |||
813 | m->m_flags |= M_SKIP_FIREWALL0x00004000; | |||
814 | fibnum = M_GETFIB(m)rt_m_getfib(m); | |||
815 | RO_INVALIDATE_CACHE(ro)do { do { if ((ro)->ro_rt) do { __mtx_lock_flags(&(((( &((ro)->ro_rt)->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (815)); do { if (((ro)->ro_rt)->rt_refcnt <= 1) rtfree ((ro)->ro_rt); else { do { __mtx_assert(&(((&((ro) ->ro_rt)->rt_mtx)))->mtx_lock, ((0x00000004)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (815)); do { if (__builtin_expect((!(((ro)->ro_rt)-> rt_refcnt > 0)), 0)) panic ("bogus refcnt %d", ((ro)->ro_rt )->rt_refcnt); } while (0); ((ro)->ro_rt)->rt_refcnt --; } while (0); __mtx_unlock_flags(&((((&((ro)->ro_rt )->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (815)); } (ro)->ro_rt = 0; } while (0); } while (0); } while (0); if ((ro)->ro_lle != ((void *)0)) { do { _rw_wlock_cookie (&((&((ro)->ro_lle)->lle_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 815); do { if (((ro)->ro_lle)->lle_refcnt == 1) ((ro) ->ro_lle)->lle_free((ro)->ro_lle); else { do { __rw_assert (&((&((ro)->ro_lle)->lle_lock))->rw_lock, (0x00000004 ), "/root/freebsd/sys/netinet6/ip6_output.c", 815); do { if ( __builtin_expect((!(((ro)->ro_lle)->lle_refcnt > 0)) , 0)) panic ("bogus refcnt %d on lle %p", ((ro)->ro_lle)-> lle_refcnt, ((ro)->ro_lle)); } while (0); ((ro)->ro_lle )->lle_refcnt--; } while (0); _rw_wunlock_cookie(&((& ((ro)->ro_lle)->lle_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 815); } ((ro)->ro_lle) = ((void *)0); } while (0); } while (0); (ro)->ro_lle = ((void *)0); } } while (0); | |||
816 | needfiblookup = 1; | |||
817 | } | |||
818 | if (needfiblookup) | |||
819 | goto again; | |||
820 | ||||
821 | /* See if local, if yes, send it to netisr. */ | |||
822 | if (m->m_flags & M_FASTFWD_OURS0x00001000) { | |||
823 | if (m->m_pkthdr.rcvif == NULL((void *)0)) | |||
824 | m->m_pkthdr.rcvif = V_loif(*(__typeof(vnet_entry_loif)*) (((((__curthread())->td_vnet ))->vnet_data_base) + (uintptr_t)&vnet_entry_loif)); | |||
825 | if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6(0x00000400|0x00000200)) { | |||
826 | m->m_pkthdr.csum_flags |= | |||
827 | CSUM_DATA_VALID_IPV60x08000000 | CSUM_PSEUDO_HDR0x04000000; | |||
828 | m->m_pkthdr.csum_dataPH_per.thirtytwo[1] = 0xffff; | |||
829 | } | |||
830 | #ifdef SCTP1 | |||
831 | if (m->m_pkthdr.csum_flags & CSUM_SCTP_IPV60x00000800) | |||
832 | m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID0x08000000; | |||
833 | #endif | |||
834 | error = netisr_queue(NETISR_IPV66, m); | |||
835 | goto done; | |||
836 | } | |||
837 | /* Or forward to some other address? */ | |||
838 | if ((m->m_flags & M_IP6_NEXTHOP0x00002000) && | |||
839 | (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD18, NULL((void *)0))) != NULL((void *)0)) { | |||
840 | dst = (struct sockaddr_in6 *)&ro->ro_dst; | |||
841 | bcopy((fwd_tag+1), &dst_sa, sizeof(struct sockaddr_in6))__builtin_memmove((&dst_sa), ((fwd_tag+1)), (sizeof(struct sockaddr_in6))); | |||
842 | m->m_flags |= M_SKIP_FIREWALL0x00004000; | |||
843 | m->m_flags &= ~M_IP6_NEXTHOP0x00002000; | |||
844 | m_tag_delete(m, fwd_tag); | |||
845 | goto again; | |||
846 | } | |||
847 | ||||
848 | passout: | |||
849 | /* | |||
850 | * Send the packet to the outgoing interface. | |||
851 | * If necessary, do IPv6 fragmentation before sending. | |||
852 | * | |||
853 | * the logic here is rather complex: | |||
854 | * 1: normal case (dontfrag == 0, alwaysfrag == 0) | |||
855 | * 1-a: send as is if tlen <= path mtu | |||
856 | * 1-b: fragment if tlen > path mtu | |||
857 | * | |||
858 | * 2: if user asks us not to fragment (dontfrag == 1) | |||
859 | * 2-a: send as is if tlen <= interface mtu | |||
860 | * 2-b: error if tlen > interface mtu | |||
861 | * | |||
862 | * 3: if we always need to attach fragment header (alwaysfrag == 1) | |||
863 | * always fragment | |||
864 | * | |||
865 | * 4: if dontfrag == 1 && alwaysfrag == 1 | |||
866 | * error, as we cannot handle this conflicting request | |||
867 | */ | |||
868 | sw_csum = m->m_pkthdr.csum_flags; | |||
869 | if (!hdrsplit) { | |||
870 | tso = ((sw_csum & ifp->if_hwassist & CSUM_TSO(0x00000010|0x00001000)) != 0) ? 1 : 0; | |||
871 | sw_csum &= ~ifp->if_hwassist; | |||
872 | } else | |||
873 | tso = 0; | |||
874 | /* | |||
875 | * If we added extension headers, we will not do TSO and calculate the | |||
876 | * checksums ourselves for now. | |||
877 | * XXX-BZ Need a framework to know when the NIC can handle it, even | |||
878 | * with ext. hdrs. | |||
879 | */ | |||
880 | if (sw_csum & CSUM_DELAY_DATA_IPV6(0x00000400|0x00000200)) { | |||
881 | sw_csum &= ~CSUM_DELAY_DATA_IPV6(0x00000400|0x00000200); | |||
882 | in6_delayed_cksum(m, plen, sizeof(struct ip6_hdr)); | |||
883 | } | |||
884 | #ifdef SCTP1 | |||
885 | if (sw_csum & CSUM_SCTP_IPV60x00000800) { | |||
886 | sw_csum &= ~CSUM_SCTP_IPV60x00000800; | |||
887 | sctp_delayed_cksum(m, sizeof(struct ip6_hdr)); | |||
888 | } | |||
889 | #endif | |||
890 | m->m_pkthdr.csum_flags &= ifp->if_hwassist; | |||
891 | tlen = m->m_pkthdr.len; | |||
892 | ||||
893 | if ((opt && (opt->ip6po_flags & IP6PO_DONTFRAG0x04)) || tso) | |||
894 | dontfrag = 1; | |||
895 | else | |||
896 | dontfrag = 0; | |||
897 | if (dontfrag && alwaysfrag) { /* case 4 */ | |||
898 | /* conflicting request - can't transmit */ | |||
899 | error = EMSGSIZE40; | |||
900 | goto bad; | |||
901 | } | |||
902 | if (dontfrag && tlen > IN6_LINKMTU(ifp)(((((struct in6_ifextra *)(ifp)->if_afdata[28])->nd_ifinfo )->linkmtu && (((struct in6_ifextra *)(ifp)->if_afdata [28])->nd_ifinfo)->linkmtu < (ifp)->if_mtu) ? ((( struct in6_ifextra *)(ifp)->if_afdata[28])->nd_ifinfo)-> linkmtu : (((((struct in6_ifextra *)(ifp)->if_afdata[28])-> nd_ifinfo)->maxmtu && (((struct in6_ifextra *)(ifp )->if_afdata[28])->nd_ifinfo)->maxmtu < (ifp)-> if_mtu) ? (((struct in6_ifextra *)(ifp)->if_afdata[28])-> nd_ifinfo)->maxmtu : (ifp)->if_mtu)) && !tso) { /* case 2-b */ | |||
903 | /* | |||
904 | * Even if the DONTFRAG option is specified, we cannot send the | |||
905 | * packet when the data length is larger than the MTU of the | |||
906 | * outgoing interface. | |||
907 | * Notify the error by sending IPV6_PATHMTU ancillary data if | |||
908 | * application wanted to know the MTU value. Also return an | |||
909 | * error code (this is not described in the API spec). | |||
910 | */ | |||
911 | if (inp != NULL((void *)0)) | |||
912 | ip6_notify_pmtu(inp, &dst_sa, (u_int32_t)mtu); | |||
913 | error = EMSGSIZE40; | |||
914 | goto bad; | |||
915 | } | |||
916 | ||||
917 | /* | |||
918 | * transmit packet without fragmentation | |||
919 | */ | |||
920 | if (dontfrag || (!alwaysfrag && tlen <= mtu)) { /* case 1-a and 2-a */ | |||
921 | struct in6_ifaddr *ia6; | |||
922 | ||||
923 | ip6 = mtod(m, struct ip6_hdr *)((struct ip6_hdr *)((m)->m_data)); | |||
924 | ia6 = in6_ifawithifp(ifp, &ip6->ip6_src); | |||
925 | if (ia6) { | |||
926 | /* Record statistics for this interface address. */ | |||
927 | counter_u64_add(ia6->ia_ifa.ifa_opackets, 1); | |||
928 | counter_u64_add(ia6->ia_ifa.ifa_obytes, | |||
929 | m->m_pkthdr.len); | |||
930 | ifa_free(&ia6->ia_ifa); | |||
931 | } | |||
932 | #ifdef RATELIMIT | |||
933 | if (inp != NULL((void *)0)) { | |||
934 | if (inp->inp_flags2 & INP_RATE_LIMIT_CHANGED0x00000400) | |||
935 | in_pcboutput_txrtlmt(inp, ifp, m); | |||
936 | /* stamp send tag on mbuf */ | |||
937 | m->m_pkthdr.snd_tag = inp->inp_snd_tag; | |||
938 | } else { | |||
939 | m->m_pkthdr.snd_tag = NULL((void *)0); | |||
940 | } | |||
941 | #endif | |||
942 | error = nd6_output_ifp(ifp, origifp, m, dst, | |||
943 | (struct route *)ro); | |||
944 | #ifdef RATELIMIT | |||
945 | /* check for route change */ | |||
946 | if (error == EAGAIN35) | |||
947 | in_pcboutput_eagain(inp); | |||
948 | #endif | |||
949 | goto done; | |||
950 | } | |||
951 | ||||
952 | /* | |||
953 | * try to fragment the packet. case 1-b and 3 | |||
954 | */ | |||
955 | if (mtu < IPV6_MMTU1280) { | |||
956 | /* path MTU cannot be less than IPV6_MMTU */ | |||
957 | error = EMSGSIZE40; | |||
958 | in6_ifstat_inc(ifp, ifs6_out_fragfail)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_fragfail) / sizeof(uint64_t)], 1);} while ( 0); | |||
959 | goto bad; | |||
960 | } else if (ip6->ip6_plenip6_ctlun.ip6_un1.ip6_un1_plen == 0) { | |||
961 | /* jumbo payload cannot be fragmented */ | |||
962 | error = EMSGSIZE40; | |||
963 | in6_ifstat_inc(ifp, ifs6_out_fragfail)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_fragfail) / sizeof(uint64_t)], 1);} while ( 0); | |||
964 | goto bad; | |||
965 | } else { | |||
966 | u_char nextproto; | |||
967 | ||||
968 | /* | |||
969 | * Too large for the destination or interface; | |||
970 | * fragment if possible. | |||
971 | * Must be able to put at least 8 bytes per fragment. | |||
972 | */ | |||
973 | hlen = unfragpartlen; | |||
974 | if (mtu > IPV6_MAXPACKET65535) | |||
975 | mtu = IPV6_MAXPACKET65535; | |||
976 | ||||
977 | len = (mtu - hlen - sizeof(struct ip6_frag)) & ~7; | |||
978 | if (len < 8) { | |||
979 | error = EMSGSIZE40; | |||
980 | in6_ifstat_inc(ifp, ifs6_out_fragfail)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_fragfail) / sizeof(uint64_t)], 1);} while ( 0); | |||
981 | goto bad; | |||
982 | } | |||
983 | ||||
984 | /* | |||
985 | * If the interface will not calculate checksums on | |||
986 | * fragmented packets, then do it here. | |||
987 | * XXX-BZ handle the hw offloading case. Need flags. | |||
988 | */ | |||
989 | if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6(0x00000400|0x00000200)) { | |||
990 | in6_delayed_cksum(m, plen, hlen); | |||
991 | m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6(0x00000400|0x00000200); | |||
992 | } | |||
993 | #ifdef SCTP1 | |||
994 | if (m->m_pkthdr.csum_flags & CSUM_SCTP_IPV60x00000800) { | |||
995 | sctp_delayed_cksum(m, hlen); | |||
996 | m->m_pkthdr.csum_flags &= ~CSUM_SCTP_IPV60x00000800; | |||
997 | } | |||
998 | #endif | |||
999 | /* | |||
1000 | * Change the next header field of the last header in the | |||
1001 | * unfragmentable part. | |||
1002 | */ | |||
1003 | if (exthdrs.ip6e_rthdr) { | |||
1004 | nextproto = *mtod(exthdrs.ip6e_rthdr, u_char *)((u_char *)((exthdrs.ip6e_rthdr)->m_data)); | |||
1005 | *mtod(exthdrs.ip6e_rthdr, u_char *)((u_char *)((exthdrs.ip6e_rthdr)->m_data)) = IPPROTO_FRAGMENT44; | |||
1006 | } else if (exthdrs.ip6e_dest1) { | |||
1007 | nextproto = *mtod(exthdrs.ip6e_dest1, u_char *)((u_char *)((exthdrs.ip6e_dest1)->m_data)); | |||
1008 | *mtod(exthdrs.ip6e_dest1, u_char *)((u_char *)((exthdrs.ip6e_dest1)->m_data)) = IPPROTO_FRAGMENT44; | |||
1009 | } else if (exthdrs.ip6e_hbh) { | |||
1010 | nextproto = *mtod(exthdrs.ip6e_hbh, u_char *)((u_char *)((exthdrs.ip6e_hbh)->m_data)); | |||
1011 | *mtod(exthdrs.ip6e_hbh, u_char *)((u_char *)((exthdrs.ip6e_hbh)->m_data)) = IPPROTO_FRAGMENT44; | |||
1012 | } else { | |||
1013 | nextproto = ip6->ip6_nxtip6_ctlun.ip6_un1.ip6_un1_nxt; | |||
1014 | ip6->ip6_nxtip6_ctlun.ip6_un1.ip6_un1_nxt = IPPROTO_FRAGMENT44; | |||
1015 | } | |||
1016 | ||||
1017 | /* | |||
1018 | * Loop through length of segment after first fragment, | |||
1019 | * make new header and copy data of each part and link onto | |||
1020 | * chain. | |||
1021 | */ | |||
1022 | m0 = m; | |||
1023 | id = htonl(ip6_randomid())(__builtin_constant_p(ip6_randomid()) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)(ip6_randomid())) & 0xffff ) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(ip6_randomid())) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(ip6_randomid ())) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t) (ip6_randomid())) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(ip6_randomid())) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(ip6_randomid( ))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(ip6_randomid ())) >> 16)) >> 8) : __bswap16_var(((__uint32_t)( ip6_randomid())) >> 16)))) : __bswap32_var(ip6_randomid ())); | |||
1024 | if ((error = ip6_fragment(ifp, m, hlen, nextproto, len, id))) | |||
1025 | goto sendorfree; | |||
1026 | ||||
1027 | in6_ifstat_inc(ifp, ifs6_out_fragok)do { if (ifp) counter_u64_add(((struct in6_ifextra *) ((ifp)-> if_afdata[28]))->in6_ifstat[ __builtin_offsetof(struct in6_ifstat , ifs6_out_fragok) / sizeof(uint64_t)], 1);} while ( 0); | |||
1028 | } | |||
1029 | ||||
1030 | /* | |||
1031 | * Remove leading garbages. | |||
1032 | */ | |||
1033 | sendorfree: | |||
1034 | m = m0->m_nextpkt; | |||
1035 | m0->m_nextpkt = 0; | |||
1036 | m_freem(m0); | |||
1037 | for (; m; m = m0) { | |||
1038 | m0 = m->m_nextpkt; | |||
1039 | m->m_nextpkt = 0; | |||
1040 | if (error == 0) { | |||
1041 | /* Record statistics for this interface address. */ | |||
1042 | if (ia) { | |||
1043 | counter_u64_add(ia->ia_ifa.ifa_opackets, 1); | |||
1044 | counter_u64_add(ia->ia_ifa.ifa_obytes, | |||
1045 | m->m_pkthdr.len); | |||
1046 | } | |||
1047 | #ifdef RATELIMIT | |||
1048 | if (inp != NULL((void *)0)) { | |||
1049 | if (inp->inp_flags2 & INP_RATE_LIMIT_CHANGED0x00000400) | |||
1050 | in_pcboutput_txrtlmt(inp, ifp, m); | |||
1051 | /* stamp send tag on mbuf */ | |||
1052 | m->m_pkthdr.snd_tag = inp->inp_snd_tag; | |||
1053 | } else { | |||
1054 | m->m_pkthdr.snd_tag = NULL((void *)0); | |||
1055 | } | |||
1056 | #endif | |||
1057 | error = nd6_output_ifp(ifp, origifp, m, dst, | |||
1058 | (struct route *)ro); | |||
1059 | #ifdef RATELIMIT | |||
1060 | /* check for route change */ | |||
1061 | if (error == EAGAIN35) | |||
1062 | in_pcboutput_eagain(inp); | |||
1063 | #endif | |||
1064 | } else | |||
1065 | m_freem(m); | |||
1066 | } | |||
1067 | ||||
1068 | if (error == 0) | |||
1069 | IP6STAT_INC(ip6s_fragmented)counter_u64_add((*(__typeof(vnet_entry_ip6stat)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6stat ))[__builtin_offsetof(struct ip6stat, ip6s_fragmented) / sizeof (uint64_t)], ((1))); | |||
1070 | ||||
1071 | done: | |||
1072 | if (ro == &ip6route) | |||
1073 | RO_RTFREE(ro)do { if ((ro)->ro_rt) do { __mtx_lock_flags(&((((& ((ro)->ro_rt)->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (1073)); do { if (((ro)->ro_rt)->rt_refcnt <= 1) rtfree ((ro)->ro_rt); else { do { __mtx_assert(&(((&((ro) ->ro_rt)->rt_mtx)))->mtx_lock, ((0x00000004)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (1073)); do { if (__builtin_expect((!(((ro)->ro_rt)-> rt_refcnt > 0)), 0)) panic ("bogus refcnt %d", ((ro)->ro_rt )->rt_refcnt); } while (0); ((ro)->ro_rt)->rt_refcnt --; } while (0); __mtx_unlock_flags(&((((&((ro)->ro_rt )->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (1073)); } (ro)->ro_rt = 0; } while (0); } while (0); } while (0); | |||
1074 | return (error); | |||
1075 | ||||
1076 | freehdrs: | |||
1077 | m_freem(exthdrs.ip6e_hbh); /* m_freem will check if mbuf is 0 */ | |||
1078 | m_freem(exthdrs.ip6e_dest1); | |||
1079 | m_freem(exthdrs.ip6e_rthdr); | |||
1080 | m_freem(exthdrs.ip6e_dest2); | |||
1081 | /* FALLTHROUGH */ | |||
1082 | bad: | |||
1083 | if (m) | |||
1084 | m_freem(m); | |||
1085 | goto done; | |||
1086 | } | |||
1087 | ||||
1088 | static int | |||
1089 | ip6_copyexthdr(struct mbuf **mp, caddr_t hdr, int hlen) | |||
1090 | { | |||
1091 | struct mbuf *m; | |||
1092 | ||||
1093 | if (hlen > MCLBYTES(1 << 11)) | |||
1094 | return (ENOBUFS55); /* XXX */ | |||
1095 | ||||
1096 | if (hlen > MLEN((int)(256 - __builtin_offsetof(struct mbuf, m_dat)))) | |||
1097 | m = m_getcl(M_NOWAIT0x0001, MT_DATA1, 0); | |||
1098 | else | |||
1099 | m = m_get(M_NOWAIT0x0001, MT_DATA1); | |||
1100 | if (m == NULL((void *)0)) | |||
1101 | return (ENOBUFS55); | |||
1102 | m->m_len = hlen; | |||
1103 | if (hdr) | |||
1104 | bcopy(hdr, mtod(m, caddr_t), hlen)__builtin_memmove((((caddr_t)((m)->m_data))), (hdr), (hlen )); | |||
1105 | ||||
1106 | *mp = m; | |||
1107 | return (0); | |||
1108 | } | |||
1109 | ||||
1110 | /* | |||
1111 | * Insert jumbo payload option. | |||
1112 | */ | |||
1113 | static int | |||
1114 | ip6_insert_jumboopt(struct ip6_exthdrs *exthdrs, u_int32_t plen) | |||
1115 | { | |||
1116 | struct mbuf *mopt; | |||
1117 | u_char *optbuf; | |||
1118 | u_int32_t v; | |||
1119 | ||||
1120 | #define JUMBOOPTLEN 8 /* length of jumbo payload option and padding */ | |||
1121 | ||||
1122 | /* | |||
1123 | * If there is no hop-by-hop options header, allocate new one. | |||
1124 | * If there is one but it doesn't have enough space to store the | |||
1125 | * jumbo payload option, allocate a cluster to store the whole options. | |||
1126 | * Otherwise, use it to store the options. | |||
1127 | */ | |||
1128 | if (exthdrs->ip6e_hbh == NULL((void *)0)) { | |||
1129 | mopt = m_get(M_NOWAIT0x0001, MT_DATA1); | |||
1130 | if (mopt == NULL((void *)0)) | |||
1131 | return (ENOBUFS55); | |||
1132 | mopt->m_len = JUMBOOPTLEN; | |||
1133 | optbuf = mtod(mopt, u_char *)((u_char *)((mopt)->m_data)); | |||
1134 | optbuf[1] = 0; /* = ((JUMBOOPTLEN) >> 3) - 1 */ | |||
1135 | exthdrs->ip6e_hbh = mopt; | |||
1136 | } else { | |||
1137 | struct ip6_hbh *hbh; | |||
1138 | ||||
1139 | mopt = exthdrs->ip6e_hbh; | |||
1140 | if (M_TRAILINGSPACE(mopt)((!((mopt)->m_flags & 0x00000008) && (!(((mopt )->m_flags & 0x00000001)) || (m_extrefcnt(mopt) == 1)) ) ? (((((mopt)->m_flags & 0x00000001) ? (mopt)->m_ext .ext_buf : ((mopt)->m_flags & 0x00000002) ? &(mopt )->m_pktdat[0] : &(mopt)->m_dat[0]) + (((mopt)-> m_flags & 0x00000001) ? (mopt)->m_ext.ext_size : ((mopt )->m_flags & 0x00000002) ? ((int)(256 - __builtin_offsetof (struct mbuf, m_pktdat))) : ((int)(256 - __builtin_offsetof(struct mbuf, m_dat))))) - ((mopt)->m_data + (mopt)->m_len)) : 0) < JUMBOOPTLEN) { | |||
1141 | /* | |||
1142 | * XXX assumption: | |||
1143 | * - exthdrs->ip6e_hbh is not referenced from places | |||
1144 | * other than exthdrs. | |||
1145 | * - exthdrs->ip6e_hbh is not an mbuf chain. | |||
1146 | */ | |||
1147 | int oldoptlen = mopt->m_len; | |||
1148 | struct mbuf *n; | |||
1149 | ||||
1150 | /* | |||
1151 | * XXX: give up if the whole (new) hbh header does | |||
1152 | * not fit even in an mbuf cluster. | |||
1153 | */ | |||
1154 | if (oldoptlen + JUMBOOPTLEN > MCLBYTES(1 << 11)) | |||
1155 | return (ENOBUFS55); | |||
1156 | ||||
1157 | /* | |||
1158 | * As a consequence, we must always prepare a cluster | |||
1159 | * at this point. | |||
1160 | */ | |||
1161 | n = m_getcl(M_NOWAIT0x0001, MT_DATA1, 0); | |||
1162 | if (n == NULL((void *)0)) | |||
1163 | return (ENOBUFS55); | |||
1164 | n->m_len = oldoptlen + JUMBOOPTLEN; | |||
1165 | bcopy(mtod(mopt, caddr_t), mtod(n, caddr_t),__builtin_memmove((((caddr_t)((n)->m_data))), (((caddr_t)( (mopt)->m_data))), (oldoptlen)) | |||
1166 | oldoptlen)__builtin_memmove((((caddr_t)((n)->m_data))), (((caddr_t)( (mopt)->m_data))), (oldoptlen)); | |||
1167 | optbuf = mtod(n, caddr_t)((caddr_t)((n)->m_data)) + oldoptlen; | |||
1168 | m_freem(mopt); | |||
1169 | mopt = exthdrs->ip6e_hbh = n; | |||
1170 | } else { | |||
1171 | optbuf = mtod(mopt, u_char *)((u_char *)((mopt)->m_data)) + mopt->m_len; | |||
1172 | mopt->m_len += JUMBOOPTLEN; | |||
1173 | } | |||
1174 | optbuf[0] = IP6OPT_PADN0x01; | |||
1175 | optbuf[1] = 1; | |||
1176 | ||||
1177 | /* | |||
1178 | * Adjust the header length according to the pad and | |||
1179 | * the jumbo payload option. | |||
1180 | */ | |||
1181 | hbh = mtod(mopt, struct ip6_hbh *)((struct ip6_hbh *)((mopt)->m_data)); | |||
1182 | hbh->ip6h_len += (JUMBOOPTLEN >> 3); | |||
1183 | } | |||
1184 | ||||
1185 | /* fill in the option. */ | |||
1186 | optbuf[2] = IP6OPT_JUMBO0xC2; | |||
1187 | optbuf[3] = 4; | |||
1188 | v = (u_int32_t)htonl(plen + JUMBOOPTLEN)(__builtin_constant_p(plen + JUMBOOPTLEN) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)(plen + JUMBOOPTLEN)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(plen + JUMBOOPTLEN )) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(plen + JUMBOOPTLEN)) & 0xffff)) >> 8) : __bswap16_var(( (__uint32_t)(plen + JUMBOOPTLEN)) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(plen + JUMBOOPTLEN )) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(plen + JUMBOOPTLEN)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )(plen + JUMBOOPTLEN)) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(plen + JUMBOOPTLEN)) >> 16)))) : __bswap32_var (plen + JUMBOOPTLEN)); | |||
1189 | bcopy(&v, &optbuf[4], sizeof(u_int32_t))__builtin_memmove((&optbuf[4]), (&v), (sizeof(u_int32_t ))); | |||
1190 | ||||
1191 | /* finally, adjust the packet header length */ | |||
1192 | exthdrs->ip6e_ip6->m_pkthdr.len += JUMBOOPTLEN; | |||
1193 | ||||
1194 | return (0); | |||
1195 | #undef JUMBOOPTLEN | |||
1196 | } | |||
1197 | ||||
1198 | /* | |||
1199 | * Insert fragment header and copy unfragmentable header portions. | |||
1200 | */ | |||
1201 | static int | |||
1202 | ip6_insertfraghdr(struct mbuf *m0, struct mbuf *m, int hlen, | |||
1203 | struct ip6_frag **frghdrp) | |||
1204 | { | |||
1205 | struct mbuf *n, *mlast; | |||
1206 | ||||
1207 | if (hlen > sizeof(struct ip6_hdr)) { | |||
1208 | n = m_copym(m0, sizeof(struct ip6_hdr), | |||
1209 | hlen - sizeof(struct ip6_hdr), M_NOWAIT0x0001); | |||
1210 | if (n == NULL((void *)0)) | |||
1211 | return (ENOBUFS55); | |||
1212 | m->m_next = n; | |||
1213 | } else | |||
1214 | n = m; | |||
1215 | ||||
1216 | /* Search for the last mbuf of unfragmentable part. */ | |||
1217 | for (mlast = n; mlast->m_next; mlast = mlast->m_next) | |||
1218 | ; | |||
1219 | ||||
1220 | if (M_WRITABLE(mlast)(!((mlast)->m_flags & 0x00000008) && (!(((mlast )->m_flags & 0x00000001)) || (m_extrefcnt(mlast) == 1) )) && | |||
1221 | M_TRAILINGSPACE(mlast)((!((mlast)->m_flags & 0x00000008) && (!(((mlast )->m_flags & 0x00000001)) || (m_extrefcnt(mlast) == 1) )) ? (((((mlast)->m_flags & 0x00000001) ? (mlast)-> m_ext.ext_buf : ((mlast)->m_flags & 0x00000002) ? & (mlast)->m_pktdat[0] : &(mlast)->m_dat[0]) + (((mlast )->m_flags & 0x00000001) ? (mlast)->m_ext.ext_size : ((mlast)->m_flags & 0x00000002) ? ((int)(256 - __builtin_offsetof (struct mbuf, m_pktdat))) : ((int)(256 - __builtin_offsetof(struct mbuf, m_dat))))) - ((mlast)->m_data + (mlast)->m_len)) : 0) >= sizeof(struct ip6_frag)) { | |||
1222 | /* use the trailing space of the last mbuf for the fragment hdr */ | |||
1223 | *frghdrp = (struct ip6_frag *)(mtod(mlast, caddr_t)((caddr_t)((mlast)->m_data)) + | |||
1224 | mlast->m_len); | |||
1225 | mlast->m_len += sizeof(struct ip6_frag); | |||
1226 | m->m_pkthdr.len += sizeof(struct ip6_frag); | |||
1227 | } else { | |||
1228 | /* allocate a new mbuf for the fragment header */ | |||
1229 | struct mbuf *mfrg; | |||
1230 | ||||
1231 | mfrg = m_get(M_NOWAIT0x0001, MT_DATA1); | |||
1232 | if (mfrg == NULL((void *)0)) | |||
1233 | return (ENOBUFS55); | |||
1234 | mfrg->m_len = sizeof(struct ip6_frag); | |||
1235 | *frghdrp = mtod(mfrg, struct ip6_frag *)((struct ip6_frag *)((mfrg)->m_data)); | |||
1236 | mlast->m_next = mfrg; | |||
1237 | } | |||
1238 | ||||
1239 | return (0); | |||
1240 | } | |||
1241 | ||||
1242 | /* | |||
1243 | * Calculates IPv6 path mtu for destination @dst. | |||
1244 | * Resulting MTU is stored in @mtup. | |||
1245 | * | |||
1246 | * Returns 0 on success. | |||
1247 | */ | |||
1248 | static int | |||
1249 | ip6_getpmtu_ctl(u_int fibnum, const struct in6_addr *dst, u_long *mtup) | |||
1250 | { | |||
1251 | struct nhop6_extended nh6; | |||
1252 | struct in6_addr kdst; | |||
1253 | uint32_t scopeid; | |||
1254 | struct ifnet *ifp; | |||
1255 | u_long mtu; | |||
1256 | int error; | |||
1257 | ||||
1258 | in6_splitscope(dst, &kdst, &scopeid); | |||
1259 | if (fib6_lookup_nh_ext(fibnum, &kdst, scopeid, NHR_REF0x02, 0, &nh6) != 0) | |||
1260 | return (EHOSTUNREACH65); | |||
1261 | ||||
1262 | ifp = nh6.nh_ifp; | |||
1263 | mtu = nh6.nh_mtu; | |||
1264 | ||||
1265 | error = ip6_calcmtu(ifp, dst, mtu, mtup, NULL((void *)0), 0); | |||
1266 | fib6_free_nh_ext(fibnum, &nh6); | |||
1267 | ||||
1268 | return (error); | |||
1269 | } | |||
1270 | ||||
1271 | /* | |||
1272 | * Calculates IPv6 path MTU for @dst based on transmit @ifp, | |||
1273 | * and cached data in @ro_pmtu. | |||
1274 | * MTU from (successful) route lookup is saved (along with dst) | |||
1275 | * inside @ro_pmtu to avoid subsequent route lookups after packet | |||
1276 | * filter processing. | |||
1277 | * | |||
1278 | * Stores mtu and always-frag value into @mtup and @alwaysfragp. | |||
1279 | * Returns 0 on success. | |||
1280 | */ | |||
1281 | static int | |||
1282 | ip6_getpmtu(struct route_in6 *ro_pmtu, int do_lookup, | |||
1283 | struct ifnet *ifp, const struct in6_addr *dst, u_long *mtup, | |||
1284 | int *alwaysfragp, u_int fibnum, u_int proto) | |||
1285 | { | |||
1286 | struct nhop6_basic nh6; | |||
1287 | struct in6_addr kdst; | |||
1288 | uint32_t scopeid; | |||
1289 | struct sockaddr_in6 *sa6_dst; | |||
1290 | u_long mtu; | |||
1291 | ||||
1292 | mtu = 0; | |||
1293 | if (do_lookup) { | |||
1294 | ||||
1295 | /* | |||
1296 | * Here ro_pmtu has final destination address, while | |||
1297 | * ro might represent immediate destination. | |||
1298 | * Use ro_pmtu destination since mtu might differ. | |||
1299 | */ | |||
1300 | sa6_dst = (struct sockaddr_in6 *)&ro_pmtu->ro_dst; | |||
1301 | if (!IN6_ARE_ADDR_EQUAL(&sa6_dst->sin6_addr, dst)(__builtin_memcmp((&(&sa6_dst->sin6_addr)->__u6_addr .__u6_addr8[0]), (&(dst)->__u6_addr.__u6_addr8[0]), (sizeof (struct in6_addr))) == 0)) | |||
1302 | ro_pmtu->ro_mtu = 0; | |||
1303 | ||||
1304 | if (ro_pmtu->ro_mtu == 0) { | |||
1305 | bzero(sa6_dst, sizeof(*sa6_dst))__builtin_memset((sa6_dst), 0, (sizeof(*sa6_dst))); | |||
1306 | sa6_dst->sin6_family = AF_INET628; | |||
1307 | sa6_dst->sin6_len = sizeof(struct sockaddr_in6); | |||
1308 | sa6_dst->sin6_addr = *dst; | |||
1309 | ||||
1310 | in6_splitscope(dst, &kdst, &scopeid); | |||
1311 | if (fib6_lookup_nh_basic(fibnum, &kdst, scopeid, 0, 0, | |||
1312 | &nh6) == 0) | |||
1313 | ro_pmtu->ro_mtu = nh6.nh_mtu; | |||
1314 | } | |||
1315 | ||||
1316 | mtu = ro_pmtu->ro_mtu; | |||
1317 | } | |||
1318 | ||||
1319 | if (ro_pmtu->ro_rt) | |||
1320 | mtu = ro_pmtu->ro_rt->rt_mtu; | |||
1321 | ||||
1322 | return (ip6_calcmtu(ifp, dst, mtu, mtup, alwaysfragp, proto)); | |||
1323 | } | |||
1324 | ||||
1325 | /* | |||
1326 | * Calculate MTU based on transmit @ifp, route mtu @rt_mtu and | |||
1327 | * hostcache data for @dst. | |||
1328 | * Stores mtu and always-frag value into @mtup and @alwaysfragp. | |||
1329 | * | |||
1330 | * Returns 0 on success. | |||
1331 | */ | |||
1332 | static int | |||
1333 | ip6_calcmtu(struct ifnet *ifp, const struct in6_addr *dst, u_long rt_mtu, | |||
1334 | u_long *mtup, int *alwaysfragp, u_int proto) | |||
1335 | { | |||
1336 | u_long mtu = 0; | |||
1337 | int alwaysfrag = 0; | |||
1338 | int error = 0; | |||
1339 | ||||
1340 | if (rt_mtu > 0) { | |||
1341 | u_int32_t ifmtu; | |||
1342 | struct in_conninfo inc; | |||
1343 | ||||
1344 | bzero(&inc, sizeof(inc))__builtin_memset((&inc), 0, (sizeof(inc))); | |||
1345 | inc.inc_flags |= INC_ISIPV60x01; | |||
1346 | inc.inc6_faddrinc_ie.ie_dependfaddr.id6_addr = *dst; | |||
1347 | ||||
1348 | ifmtu = IN6_LINKMTU(ifp)(((((struct in6_ifextra *)(ifp)->if_afdata[28])->nd_ifinfo )->linkmtu && (((struct in6_ifextra *)(ifp)->if_afdata [28])->nd_ifinfo)->linkmtu < (ifp)->if_mtu) ? ((( struct in6_ifextra *)(ifp)->if_afdata[28])->nd_ifinfo)-> linkmtu : (((((struct in6_ifextra *)(ifp)->if_afdata[28])-> nd_ifinfo)->maxmtu && (((struct in6_ifextra *)(ifp )->if_afdata[28])->nd_ifinfo)->maxmtu < (ifp)-> if_mtu) ? (((struct in6_ifextra *)(ifp)->if_afdata[28])-> nd_ifinfo)->maxmtu : (ifp)->if_mtu)); | |||
1349 | ||||
1350 | /* TCP is known to react to pmtu changes so skip hc */ | |||
1351 | if (proto != IPPROTO_TCP6) | |||
1352 | mtu = tcp_hc_getmtu(&inc); | |||
1353 | ||||
1354 | if (mtu) | |||
1355 | mtu = min(mtu, rt_mtu); | |||
1356 | else | |||
1357 | mtu = rt_mtu; | |||
1358 | if (mtu == 0) | |||
1359 | mtu = ifmtu; | |||
1360 | else if (mtu < IPV6_MMTU1280) { | |||
1361 | /* | |||
1362 | * RFC2460 section 5, last paragraph: | |||
1363 | * if we record ICMPv6 too big message with | |||
1364 | * mtu < IPV6_MMTU, transmit packets sized IPV6_MMTU | |||
1365 | * or smaller, with framgent header attached. | |||
1366 | * (fragment header is needed regardless from the | |||
1367 | * packet size, for translators to identify packets) | |||
1368 | */ | |||
1369 | alwaysfrag = 1; | |||
1370 | mtu = IPV6_MMTU1280; | |||
1371 | } | |||
1372 | } else if (ifp) { | |||
1373 | mtu = IN6_LINKMTU(ifp)(((((struct in6_ifextra *)(ifp)->if_afdata[28])->nd_ifinfo )->linkmtu && (((struct in6_ifextra *)(ifp)->if_afdata [28])->nd_ifinfo)->linkmtu < (ifp)->if_mtu) ? ((( struct in6_ifextra *)(ifp)->if_afdata[28])->nd_ifinfo)-> linkmtu : (((((struct in6_ifextra *)(ifp)->if_afdata[28])-> nd_ifinfo)->maxmtu && (((struct in6_ifextra *)(ifp )->if_afdata[28])->nd_ifinfo)->maxmtu < (ifp)-> if_mtu) ? (((struct in6_ifextra *)(ifp)->if_afdata[28])-> nd_ifinfo)->maxmtu : (ifp)->if_mtu)); | |||
1374 | } else | |||
1375 | error = EHOSTUNREACH65; /* XXX */ | |||
1376 | ||||
1377 | *mtup = mtu; | |||
1378 | if (alwaysfragp) | |||
1379 | *alwaysfragp = alwaysfrag; | |||
1380 | return (error); | |||
1381 | } | |||
1382 | ||||
1383 | /* | |||
1384 | * IP6 socket option processing. | |||
1385 | */ | |||
1386 | int | |||
1387 | ip6_ctloutput(struct socket *so, struct sockopt *sopt) | |||
1388 | { | |||
1389 | int optdatalen, uproto; | |||
1390 | void *optdata; | |||
1391 | struct inpcb *in6p = sotoinpcb(so)((struct inpcb *)(so)->so_pcb); | |||
1392 | int error, optval; | |||
1393 | int level, op, optname; | |||
1394 | int optlen; | |||
1395 | struct thread *td; | |||
1396 | #ifdef RSS | |||
1397 | uint32_t rss_bucket; | |||
1398 | int retval; | |||
1399 | #endif | |||
1400 | ||||
1401 | /* | |||
1402 | * Don't use more than a quarter of mbuf clusters. N.B.: | |||
1403 | * nmbclusters is an int, but nmbclusters * MCLBYTES may overflow | |||
1404 | * on LP64 architectures, so cast to u_long to avoid undefined | |||
1405 | * behavior. ILP32 architectures cannot have nmbclusters | |||
1406 | * large enough to overflow for other reasons. | |||
1407 | */ | |||
1408 | #define IPV6_PKTOPTIONS_MBUF_LIMIT((u_long)nmbclusters * (1 << 11) / 4) ((u_long)nmbclusters * MCLBYTES(1 << 11) / 4) | |||
1409 | ||||
1410 | level = sopt->sopt_level; | |||
1411 | op = sopt->sopt_dir; | |||
1412 | optname = sopt->sopt_name; | |||
1413 | optlen = sopt->sopt_valsize; | |||
1414 | td = sopt->sopt_td; | |||
1415 | error = 0; | |||
1416 | optval = 0; | |||
1417 | uproto = (int)so->so_proto->pr_protocol; | |||
1418 | ||||
1419 | if (level != IPPROTO_IPV641) { | |||
| ||||
1420 | error = EINVAL22; | |||
1421 | ||||
1422 | if (sopt->sopt_level == SOL_SOCKET0xffff && | |||
1423 | sopt->sopt_dir == SOPT_SET) { | |||
1424 | switch (sopt->sopt_name) { | |||
1425 | case SO_REUSEADDR0x00000004: | |||
1426 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1426); | |||
1427 | if ((so->so_options & SO_REUSEADDR0x00000004) != 0) | |||
1428 | in6p->inp_flags2 |= INP_REUSEADDR0x00000020; | |||
1429 | else | |||
1430 | in6p->inp_flags2 &= ~INP_REUSEADDR0x00000020; | |||
1431 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1431); | |||
1432 | error = 0; | |||
1433 | break; | |||
1434 | case SO_REUSEPORT0x00000200: | |||
1435 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1435); | |||
1436 | if ((so->so_options & SO_REUSEPORT0x00000200) != 0) | |||
1437 | in6p->inp_flags2 |= INP_REUSEPORT0x00000008; | |||
1438 | else | |||
1439 | in6p->inp_flags2 &= ~INP_REUSEPORT0x00000008; | |||
1440 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1440); | |||
1441 | error = 0; | |||
1442 | break; | |||
1443 | case SO_REUSEPORT_LB0x00010000: | |||
1444 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1444); | |||
1445 | if ((so->so_options & SO_REUSEPORT_LB0x00010000) != 0) | |||
1446 | in6p->inp_flags2 |= INP_REUSEPORT_LB0x00002000; | |||
1447 | else | |||
1448 | in6p->inp_flags2 &= ~INP_REUSEPORT_LB0x00002000; | |||
1449 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1449); | |||
1450 | error = 0; | |||
1451 | break; | |||
1452 | case SO_SETFIB0x1014: | |||
1453 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1453); | |||
1454 | in6p->inp_inc.inc_fibnum = so->so_fibnum; | |||
1455 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1455); | |||
1456 | error = 0; | |||
1457 | break; | |||
1458 | case SO_MAX_PACING_RATE0x1018: | |||
1459 | #ifdef RATELIMIT | |||
1460 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1460); | |||
1461 | in6p->inp_flags2 |= INP_RATE_LIMIT_CHANGED0x00000400; | |||
1462 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1462); | |||
1463 | error = 0; | |||
1464 | #else | |||
1465 | error = EOPNOTSUPP45; | |||
1466 | #endif | |||
1467 | break; | |||
1468 | default: | |||
1469 | break; | |||
1470 | } | |||
1471 | } | |||
1472 | } else { /* level == IPPROTO_IPV6 */ | |||
1473 | switch (op) { | |||
1474 | ||||
1475 | case SOPT_SET: | |||
1476 | switch (optname) { | |||
1477 | case IPV6_2292PKTOPTIONS25: | |||
1478 | #ifdef IPV6_PKTOPTIONS | |||
1479 | case IPV6_PKTOPTIONS: | |||
1480 | #endif | |||
1481 | { | |||
1482 | struct mbuf *m; | |||
1483 | ||||
1484 | if (optlen > IPV6_PKTOPTIONS_MBUF_LIMIT((u_long)nmbclusters * (1 << 11) / 4)) { | |||
1485 | printf("ip6_ctloutput: mbuf limit hit\n"); | |||
1486 | error = ENOBUFS55; | |||
1487 | break; | |||
1488 | } | |||
1489 | ||||
1490 | error = soopt_getm(sopt, &m); /* XXX */ | |||
1491 | if (error != 0) | |||
1492 | break; | |||
1493 | error = soopt_mcopyin(sopt, m); /* XXX */ | |||
1494 | if (error != 0) | |||
1495 | break; | |||
1496 | error = ip6_pcbopts(&in6p->in6p_outputopts, | |||
1497 | m, so, sopt); | |||
1498 | m_freem(m); /* XXX */ | |||
1499 | break; | |||
1500 | } | |||
1501 | ||||
1502 | /* | |||
1503 | * Use of some Hop-by-Hop options or some | |||
1504 | * Destination options, might require special | |||
1505 | * privilege. That is, normal applications | |||
1506 | * (without special privilege) might be forbidden | |||
1507 | * from setting certain options in outgoing packets, | |||
1508 | * and might never see certain options in received | |||
1509 | * packets. [RFC 2292 Section 6] | |||
1510 | * KAME specific note: | |||
1511 | * KAME prevents non-privileged users from sending or | |||
1512 | * receiving ANY hbh/dst options in order to avoid | |||
1513 | * overhead of parsing options in the kernel. | |||
1514 | */ | |||
1515 | case IPV6_RECVHOPOPTS39: | |||
1516 | case IPV6_RECVDSTOPTS40: | |||
1517 | case IPV6_RECVRTHDRDSTOPTS41: | |||
1518 | if (td != NULL((void *)0)) { | |||
1519 | error = priv_check(td, | |||
1520 | PRIV_NETINET_SETHDROPTS505); | |||
1521 | if (error) | |||
1522 | break; | |||
1523 | } | |||
1524 | /* FALLTHROUGH */ | |||
1525 | case IPV6_UNICAST_HOPS4: | |||
1526 | case IPV6_HOPLIMIT47: | |||
1527 | ||||
1528 | case IPV6_RECVPKTINFO36: | |||
1529 | case IPV6_RECVHOPLIMIT37: | |||
1530 | case IPV6_RECVRTHDR38: | |||
1531 | case IPV6_RECVPATHMTU43: | |||
1532 | case IPV6_RECVTCLASS57: | |||
1533 | case IPV6_RECVFLOWID70: | |||
1534 | #ifdef RSS | |||
1535 | case IPV6_RECVRSSBUCKETID71: | |||
1536 | #endif | |||
1537 | case IPV6_V6ONLY27: | |||
1538 | case IPV6_AUTOFLOWLABEL59: | |||
1539 | case IPV6_ORIGDSTADDR72: | |||
1540 | case IPV6_BINDANY64: | |||
1541 | case IPV6_BINDMULTI65: | |||
1542 | #ifdef RSS | |||
1543 | case IPV6_RSS_LISTEN_BUCKET66: | |||
1544 | #endif | |||
1545 | if (optname == IPV6_BINDANY64 && td != NULL((void *)0)) { | |||
1546 | error = priv_check(td, | |||
1547 | PRIV_NETINET_BINDANY506); | |||
1548 | if (error) | |||
1549 | break; | |||
1550 | } | |||
1551 | ||||
1552 | if (optlen != sizeof(int)) { | |||
1553 | error = EINVAL22; | |||
1554 | break; | |||
1555 | } | |||
1556 | error = sooptcopyin(sopt, &optval, | |||
1557 | sizeof optval, sizeof optval); | |||
1558 | if (error) | |||
1559 | break; | |||
1560 | switch (optname) { | |||
1561 | ||||
1562 | case IPV6_UNICAST_HOPS4: | |||
1563 | if (optval < -1 || optval >= 256) | |||
1564 | error = EINVAL22; | |||
1565 | else { | |||
1566 | /* -1 = kernel default */ | |||
1567 | in6p->in6p_hops = optval; | |||
1568 | if ((in6p->inp_vflag & | |||
1569 | INP_IPV40x1) != 0) | |||
1570 | in6p->inp_ip_ttl = optval; | |||
1571 | } | |||
1572 | break; | |||
1573 | #define OPTSET(bit) \ | |||
1574 | do { \ | |||
1575 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1575); \ | |||
1576 | if (optval) \ | |||
1577 | in6p->inp_flags |= (bit); \ | |||
1578 | else \ | |||
1579 | in6p->inp_flags &= ~(bit); \ | |||
1580 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1580); \ | |||
1581 | } while (/*CONSTCOND*/ 0) | |||
1582 | #define OPTSET2292(bit)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1582); in6p-> inp_flags |= 0x40000000; if (optval) in6p->inp_flags |= (bit ); else in6p->inp_flags &= ~(bit); _rw_wunlock_cookie( &((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1582); } while ( 0) \ | |||
1583 | do { \ | |||
1584 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1584); \ | |||
1585 | in6p->inp_flags |= IN6P_RFC22920x40000000; \ | |||
1586 | if (optval) \ | |||
1587 | in6p->inp_flags |= (bit); \ | |||
1588 | else \ | |||
1589 | in6p->inp_flags &= ~(bit); \ | |||
1590 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1590); \ | |||
1591 | } while (/*CONSTCOND*/ 0) | |||
1592 | #define OPTBIT(bit)(in6p->inp_flags & (bit) ? 1 : 0) (in6p->inp_flags & (bit) ? 1 : 0) | |||
1593 | ||||
1594 | #define OPTSET2_N(bit, val)do { if (val) in6p->inp_flags2 |= bit; else in6p->inp_flags2 &= ~bit; } while (0) do { \ | |||
1595 | if (val) \ | |||
1596 | in6p->inp_flags2 |= bit; \ | |||
1597 | else \ | |||
1598 | in6p->inp_flags2 &= ~bit; \ | |||
1599 | } while (0) | |||
1600 | #define OPTSET2(bit, val)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1600); do { if ( val) in6p->inp_flags2 |= bit; else in6p->inp_flags2 &= ~bit; } while (0); _rw_wunlock_cookie(&((&(in6p)-> inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1600); } while (0) do { \ | |||
1601 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1601); \ | |||
1602 | OPTSET2_N(bit, val)do { if (val) in6p->inp_flags2 |= bit; else in6p->inp_flags2 &= ~bit; } while (0); \ | |||
1603 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1603); \ | |||
1604 | } while (0) | |||
1605 | #define OPTBIT2(bit)(in6p->inp_flags2 & (bit) ? 1 : 0) (in6p->inp_flags2 & (bit) ? 1 : 0) | |||
1606 | #define OPTSET2292_EXCLUSIVE(bit)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1606); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (bit); else in6p->inp_flags &= ~(bit); } _rw_wunlock_cookie(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 1606 ); } while ( 0) \ | |||
1607 | do { \ | |||
1608 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1608); \ | |||
1609 | if (OPTBIT(IN6P_RFC2292)(in6p->inp_flags & (0x40000000) ? 1 : 0)) { \ | |||
1610 | error = EINVAL22; \ | |||
1611 | } else { \ | |||
1612 | if (optval) \ | |||
1613 | in6p->inp_flags |= (bit); \ | |||
1614 | else \ | |||
1615 | in6p->inp_flags &= ~(bit); \ | |||
1616 | } \ | |||
1617 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1617); \ | |||
1618 | } while (/*CONSTCOND*/ 0) | |||
1619 | ||||
1620 | case IPV6_RECVPKTINFO36: | |||
1621 | OPTSET2292_EXCLUSIVE(IN6P_PKTINFO)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1621); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (0x00010000); else in6p-> inp_flags &= ~(0x00010000); } _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1621); } while ( 0); | |||
1622 | break; | |||
1623 | ||||
1624 | case IPV6_HOPLIMIT47: | |||
1625 | { | |||
1626 | struct ip6_pktopts **optp; | |||
1627 | ||||
1628 | /* cannot mix with RFC2292 */ | |||
1629 | if (OPTBIT(IN6P_RFC2292)(in6p->inp_flags & (0x40000000) ? 1 : 0)) { | |||
1630 | error = EINVAL22; | |||
1631 | break; | |||
1632 | } | |||
1633 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1633); | |||
1634 | if (in6p->inp_flags & (INP_TIMEWAIT0x01000000 | INP_DROPPED0x04000000)) { | |||
1635 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1635); | |||
1636 | return (ECONNRESET54); | |||
1637 | } | |||
1638 | optp = &in6p->in6p_outputopts; | |||
1639 | error = ip6_pcbopt(IPV6_HOPLIMIT47, | |||
1640 | (u_char *)&optval, sizeof(optval), | |||
1641 | optp, (td != NULL((void *)0)) ? td->td_ucred : | |||
1642 | NULL((void *)0), uproto); | |||
1643 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1643); | |||
1644 | break; | |||
1645 | } | |||
1646 | ||||
1647 | case IPV6_RECVHOPLIMIT37: | |||
1648 | OPTSET2292_EXCLUSIVE(IN6P_HOPLIMIT)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1648); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (0x00020000); else in6p-> inp_flags &= ~(0x00020000); } _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1648); } while ( 0); | |||
1649 | break; | |||
1650 | ||||
1651 | case IPV6_RECVHOPOPTS39: | |||
1652 | OPTSET2292_EXCLUSIVE(IN6P_HOPOPTS)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1652); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (0x00040000); else in6p-> inp_flags &= ~(0x00040000); } _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1652); } while ( 0); | |||
1653 | break; | |||
1654 | ||||
1655 | case IPV6_RECVDSTOPTS40: | |||
1656 | OPTSET2292_EXCLUSIVE(IN6P_DSTOPTS)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1656); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (0x00080000); else in6p-> inp_flags &= ~(0x00080000); } _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1656); } while ( 0); | |||
1657 | break; | |||
1658 | ||||
1659 | case IPV6_RECVRTHDRDSTOPTS41: | |||
1660 | OPTSET2292_EXCLUSIVE(IN6P_RTHDRDSTOPTS)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1660); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (0x00200000); else in6p-> inp_flags &= ~(0x00200000); } _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1660); } while ( 0); | |||
1661 | break; | |||
1662 | ||||
1663 | case IPV6_RECVRTHDR38: | |||
1664 | OPTSET2292_EXCLUSIVE(IN6P_RTHDR)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1664); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (0x00100000); else in6p-> inp_flags &= ~(0x00100000); } _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1664); } while ( 0); | |||
1665 | break; | |||
1666 | ||||
1667 | case IPV6_RECVPATHMTU43: | |||
1668 | /* | |||
1669 | * We ignore this option for TCP | |||
1670 | * sockets. | |||
1671 | * (RFC3542 leaves this case | |||
1672 | * unspecified.) | |||
1673 | */ | |||
1674 | if (uproto != IPPROTO_TCP6) | |||
1675 | OPTSET(IN6P_MTU0x80000000); | |||
1676 | break; | |||
1677 | ||||
1678 | case IPV6_RECVFLOWID70: | |||
1679 | OPTSET2(INP_RECVFLOWID, optval)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1679); do { if ( optval) in6p->inp_flags2 |= 0x00000100; else in6p->inp_flags2 &= ~0x00000100; } while (0); _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1679); } while (0); | |||
1680 | break; | |||
1681 | ||||
1682 | #ifdef RSS | |||
1683 | case IPV6_RECVRSSBUCKETID71: | |||
1684 | OPTSET2(INP_RECVRSSBUCKETID, optval)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1684); do { if ( optval) in6p->inp_flags2 |= 0x00000200; else in6p->inp_flags2 &= ~0x00000200; } while (0); _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1684); } while (0); | |||
1685 | break; | |||
1686 | #endif | |||
1687 | ||||
1688 | case IPV6_V6ONLY27: | |||
1689 | /* | |||
1690 | * make setsockopt(IPV6_V6ONLY) | |||
1691 | * available only prior to bind(2). | |||
1692 | * see ipng mailing list, Jun 22 2001. | |||
1693 | */ | |||
1694 | if (in6p->inp_lportinp_inc.inc_ie.ie_lport || | |||
1695 | !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)((&in6p->inp_inc.inc_ie.ie_dependladdr.id6_addr)->__u6_addr .__u6_addr32[0] == 0 && (&in6p->inp_inc.inc_ie .ie_dependladdr.id6_addr)->__u6_addr.__u6_addr32[1] == 0 && (&in6p->inp_inc.inc_ie.ie_dependladdr.id6_addr)->__u6_addr .__u6_addr32[2] == 0 && (&in6p->inp_inc.inc_ie .ie_dependladdr.id6_addr)->__u6_addr.__u6_addr32[3] == 0)) { | |||
1696 | error = EINVAL22; | |||
1697 | break; | |||
1698 | } | |||
1699 | OPTSET(IN6P_IPV6_V6ONLY0x00008000); | |||
1700 | if (optval) | |||
1701 | in6p->inp_vflag &= ~INP_IPV40x1; | |||
1702 | else | |||
1703 | in6p->inp_vflag |= INP_IPV40x1; | |||
1704 | break; | |||
1705 | case IPV6_RECVTCLASS57: | |||
1706 | /* cannot mix with RFC2292 XXX */ | |||
1707 | OPTSET2292_EXCLUSIVE(IN6P_TCLASS)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1707); if ((in6p ->inp_flags & (0x40000000) ? 1 : 0)) { error = 22; } else { if (optval) in6p->inp_flags |= (0x00400000); else in6p-> inp_flags &= ~(0x00400000); } _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1707); } while ( 0); | |||
1708 | break; | |||
1709 | case IPV6_AUTOFLOWLABEL59: | |||
1710 | OPTSET(IN6P_AUTOFLOWLABEL0x00800000); | |||
1711 | break; | |||
1712 | ||||
1713 | case IPV6_ORIGDSTADDR72: | |||
1714 | OPTSET2(INP_ORIGDSTADDR, optval)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1714); do { if ( optval) in6p->inp_flags2 |= 0x00000800; else in6p->inp_flags2 &= ~0x00000800; } while (0); _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1714); } while (0); | |||
1715 | break; | |||
1716 | case IPV6_BINDANY64: | |||
1717 | OPTSET(INP_BINDANY0x00001000); | |||
1718 | break; | |||
1719 | ||||
1720 | case IPV6_BINDMULTI65: | |||
1721 | OPTSET2(INP_BINDMULTI, optval)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1721); do { if ( optval) in6p->inp_flags2 |= 0x00000040; else in6p->inp_flags2 &= ~0x00000040; } while (0); _rw_wunlock_cookie(&((& (in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1721); } while (0); | |||
1722 | break; | |||
1723 | #ifdef RSS | |||
1724 | case IPV6_RSS_LISTEN_BUCKET66: | |||
1725 | if ((optval >= 0) && | |||
1726 | (optval < rss_getnumbuckets())) { | |||
1727 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1727); | |||
1728 | in6p->inp_rss_listen_bucket = optval; | |||
1729 | OPTSET2_N(INP_RSS_BUCKET_SET, 1)do { if (1) in6p->inp_flags2 |= 0x00000080; else in6p-> inp_flags2 &= ~0x00000080; } while (0); | |||
1730 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1730); | |||
1731 | } else { | |||
1732 | error = EINVAL22; | |||
1733 | } | |||
1734 | break; | |||
1735 | #endif | |||
1736 | } | |||
1737 | break; | |||
1738 | ||||
1739 | case IPV6_TCLASS61: | |||
1740 | case IPV6_DONTFRAG62: | |||
1741 | case IPV6_USE_MIN_MTU42: | |||
1742 | case IPV6_PREFER_TEMPADDR63: | |||
1743 | if (optlen != sizeof(optval)) { | |||
1744 | error = EINVAL22; | |||
1745 | break; | |||
1746 | } | |||
1747 | error = sooptcopyin(sopt, &optval, | |||
1748 | sizeof optval, sizeof optval); | |||
1749 | if (error) | |||
1750 | break; | |||
1751 | { | |||
1752 | struct ip6_pktopts **optp; | |||
1753 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1753); | |||
1754 | if (in6p->inp_flags & (INP_TIMEWAIT0x01000000 | INP_DROPPED0x04000000)) { | |||
1755 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1755); | |||
1756 | return (ECONNRESET54); | |||
1757 | } | |||
1758 | optp = &in6p->in6p_outputopts; | |||
1759 | error = ip6_pcbopt(optname, | |||
1760 | (u_char *)&optval, sizeof(optval), | |||
1761 | optp, (td != NULL((void *)0)) ? td->td_ucred : | |||
1762 | NULL((void *)0), uproto); | |||
1763 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1763); | |||
1764 | break; | |||
1765 | } | |||
1766 | ||||
1767 | case IPV6_2292PKTINFO19: | |||
1768 | case IPV6_2292HOPLIMIT20: | |||
1769 | case IPV6_2292HOPOPTS22: | |||
1770 | case IPV6_2292DSTOPTS23: | |||
1771 | case IPV6_2292RTHDR24: | |||
1772 | /* RFC 2292 */ | |||
1773 | if (optlen != sizeof(int)) { | |||
1774 | error = EINVAL22; | |||
1775 | break; | |||
1776 | } | |||
1777 | error = sooptcopyin(sopt, &optval, | |||
1778 | sizeof optval, sizeof optval); | |||
1779 | if (error) | |||
1780 | break; | |||
1781 | switch (optname) { | |||
1782 | case IPV6_2292PKTINFO19: | |||
1783 | OPTSET2292(IN6P_PKTINFO)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1783); in6p-> inp_flags |= 0x40000000; if (optval) in6p->inp_flags |= (0x00010000 ); else in6p->inp_flags &= ~(0x00010000); _rw_wunlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1783); } while ( 0); | |||
1784 | break; | |||
1785 | case IPV6_2292HOPLIMIT20: | |||
1786 | OPTSET2292(IN6P_HOPLIMIT)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1786); in6p-> inp_flags |= 0x40000000; if (optval) in6p->inp_flags |= (0x00020000 ); else in6p->inp_flags &= ~(0x00020000); _rw_wunlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1786); } while ( 0); | |||
1787 | break; | |||
1788 | case IPV6_2292HOPOPTS22: | |||
1789 | /* | |||
1790 | * Check super-user privilege. | |||
1791 | * See comments for IPV6_RECVHOPOPTS. | |||
1792 | */ | |||
1793 | if (td != NULL((void *)0)) { | |||
1794 | error = priv_check(td, | |||
1795 | PRIV_NETINET_SETHDROPTS505); | |||
1796 | if (error) | |||
1797 | return (error); | |||
1798 | } | |||
1799 | OPTSET2292(IN6P_HOPOPTS)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1799); in6p-> inp_flags |= 0x40000000; if (optval) in6p->inp_flags |= (0x00040000 ); else in6p->inp_flags &= ~(0x00040000); _rw_wunlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1799); } while ( 0); | |||
1800 | break; | |||
1801 | case IPV6_2292DSTOPTS23: | |||
1802 | if (td != NULL((void *)0)) { | |||
1803 | error = priv_check(td, | |||
1804 | PRIV_NETINET_SETHDROPTS505); | |||
1805 | if (error) | |||
1806 | return (error); | |||
1807 | } | |||
1808 | OPTSET2292(IN6P_DSTOPTS|IN6P_RTHDRDSTOPTS)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1808); in6p-> inp_flags |= 0x40000000; if (optval) in6p->inp_flags |= (0x00080000 |0x00200000); else in6p->inp_flags &= ~(0x00080000|0x00200000 ); _rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1808); } while ( 0); /* XXX */ | |||
1809 | break; | |||
1810 | case IPV6_2292RTHDR24: | |||
1811 | OPTSET2292(IN6P_RTHDR)do { _rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1811); in6p-> inp_flags |= 0x40000000; if (optval) in6p->inp_flags |= (0x00100000 ); else in6p->inp_flags &= ~(0x00100000); _rw_wunlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 1811); } while ( 0); | |||
1812 | break; | |||
1813 | } | |||
1814 | break; | |||
1815 | case IPV6_PKTINFO46: | |||
1816 | case IPV6_HOPOPTS49: | |||
1817 | case IPV6_RTHDR51: | |||
1818 | case IPV6_DSTOPTS50: | |||
1819 | case IPV6_RTHDRDSTOPTS35: | |||
1820 | case IPV6_NEXTHOP48: | |||
1821 | { | |||
1822 | /* new advanced API (RFC3542) */ | |||
1823 | u_char *optbuf; | |||
1824 | u_char optbuf_storage[MCLBYTES(1 << 11)]; | |||
1825 | int optlen; | |||
1826 | struct ip6_pktopts **optp; | |||
1827 | ||||
1828 | /* cannot mix with RFC2292 */ | |||
1829 | if (OPTBIT(IN6P_RFC2292)(in6p->inp_flags & (0x40000000) ? 1 : 0)) { | |||
1830 | error = EINVAL22; | |||
1831 | break; | |||
1832 | } | |||
1833 | ||||
1834 | /* | |||
1835 | * We only ensure valsize is not too large | |||
1836 | * here. Further validation will be done | |||
1837 | * later. | |||
1838 | */ | |||
1839 | error = sooptcopyin(sopt, optbuf_storage, | |||
1840 | sizeof(optbuf_storage), 0); | |||
1841 | if (error) | |||
1842 | break; | |||
1843 | optlen = sopt->sopt_valsize; | |||
1844 | optbuf = optbuf_storage; | |||
1845 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1845); | |||
1846 | if (in6p->inp_flags & (INP_TIMEWAIT0x01000000 | INP_DROPPED0x04000000)) { | |||
1847 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1847); | |||
1848 | return (ECONNRESET54); | |||
1849 | } | |||
1850 | optp = &in6p->in6p_outputopts; | |||
1851 | error = ip6_pcbopt(optname, optbuf, optlen, | |||
1852 | optp, (td != NULL((void *)0)) ? td->td_ucred : NULL((void *)0), | |||
1853 | uproto); | |||
1854 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1854); | |||
1855 | break; | |||
1856 | } | |||
1857 | #undef OPTSET | |||
1858 | ||||
1859 | case IPV6_MULTICAST_IF9: | |||
1860 | case IPV6_MULTICAST_HOPS10: | |||
1861 | case IPV6_MULTICAST_LOOP11: | |||
1862 | case IPV6_JOIN_GROUP12: | |||
1863 | case IPV6_LEAVE_GROUP13: | |||
1864 | case IPV6_MSFILTER74: | |||
1865 | case MCAST_BLOCK_SOURCE84: | |||
1866 | case MCAST_UNBLOCK_SOURCE85: | |||
1867 | case MCAST_JOIN_GROUP80: | |||
1868 | case MCAST_LEAVE_GROUP81: | |||
1869 | case MCAST_JOIN_SOURCE_GROUP82: | |||
1870 | case MCAST_LEAVE_SOURCE_GROUP83: | |||
1871 | error = ip6_setmoptions(in6p, sopt); | |||
1872 | break; | |||
1873 | ||||
1874 | case IPV6_PORTRANGE14: | |||
1875 | error = sooptcopyin(sopt, &optval, | |||
1876 | sizeof optval, sizeof optval); | |||
1877 | if (error) | |||
1878 | break; | |||
1879 | ||||
1880 | INP_WLOCK(in6p)_rw_wlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1880); | |||
1881 | switch (optval) { | |||
1882 | case IPV6_PORTRANGE_DEFAULT0: | |||
1883 | in6p->inp_flags &= ~(INP_LOWPORT0x00000020); | |||
1884 | in6p->inp_flags &= ~(INP_HIGHPORT0x00000010); | |||
1885 | break; | |||
1886 | ||||
1887 | case IPV6_PORTRANGE_HIGH1: | |||
1888 | in6p->inp_flags &= ~(INP_LOWPORT0x00000020); | |||
1889 | in6p->inp_flags |= INP_HIGHPORT0x00000010; | |||
1890 | break; | |||
1891 | ||||
1892 | case IPV6_PORTRANGE_LOW2: | |||
1893 | in6p->inp_flags &= ~(INP_HIGHPORT0x00000010); | |||
1894 | in6p->inp_flags |= INP_LOWPORT0x00000020; | |||
1895 | break; | |||
1896 | ||||
1897 | default: | |||
1898 | error = EINVAL22; | |||
1899 | break; | |||
1900 | } | |||
1901 | INP_WUNLOCK(in6p)_rw_wunlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 1901); | |||
1902 | break; | |||
1903 | ||||
1904 | #if defined(IPSEC1) || defined(IPSEC_SUPPORT1) | |||
1905 | case IPV6_IPSEC_POLICY28: | |||
1906 | if (IPSEC_ENABLED(ipv6)((ipv6_ipsec_support)->enabled & 0x0001)) { | |||
1907 | error = IPSEC_PCBCTL(ipv6, in6p, sopt)(*(ipv6_ipsec_support)->methods->pcbctl)(in6p, sopt); | |||
1908 | break; | |||
1909 | } | |||
1910 | /* FALLTHROUGH */ | |||
1911 | #endif /* IPSEC */ | |||
1912 | ||||
1913 | default: | |||
1914 | error = ENOPROTOOPT42; | |||
1915 | break; | |||
1916 | } | |||
1917 | break; | |||
1918 | ||||
1919 | case SOPT_GET: | |||
1920 | switch (optname) { | |||
1921 | ||||
1922 | case IPV6_2292PKTOPTIONS25: | |||
1923 | #ifdef IPV6_PKTOPTIONS | |||
1924 | case IPV6_PKTOPTIONS: | |||
1925 | #endif | |||
1926 | /* | |||
1927 | * RFC3542 (effectively) deprecated the | |||
1928 | * semantics of the 2292-style pktoptions. | |||
1929 | * Since it was not reliable in nature (i.e., | |||
1930 | * applications had to expect the lack of some | |||
1931 | * information after all), it would make sense | |||
1932 | * to simplify this part by always returning | |||
1933 | * empty data. | |||
1934 | */ | |||
1935 | sopt->sopt_valsize = 0; | |||
1936 | break; | |||
1937 | ||||
1938 | case IPV6_RECVHOPOPTS39: | |||
1939 | case IPV6_RECVDSTOPTS40: | |||
1940 | case IPV6_RECVRTHDRDSTOPTS41: | |||
1941 | case IPV6_UNICAST_HOPS4: | |||
1942 | case IPV6_RECVPKTINFO36: | |||
1943 | case IPV6_RECVHOPLIMIT37: | |||
1944 | case IPV6_RECVRTHDR38: | |||
1945 | case IPV6_RECVPATHMTU43: | |||
1946 | ||||
1947 | case IPV6_V6ONLY27: | |||
1948 | case IPV6_PORTRANGE14: | |||
1949 | case IPV6_RECVTCLASS57: | |||
1950 | case IPV6_AUTOFLOWLABEL59: | |||
1951 | case IPV6_BINDANY64: | |||
1952 | case IPV6_FLOWID67: | |||
1953 | case IPV6_FLOWTYPE68: | |||
1954 | case IPV6_RECVFLOWID70: | |||
1955 | #ifdef RSS | |||
1956 | case IPV6_RSSBUCKETID69: | |||
1957 | case IPV6_RECVRSSBUCKETID71: | |||
1958 | #endif | |||
1959 | case IPV6_BINDMULTI65: | |||
1960 | switch (optname) { | |||
1961 | ||||
1962 | case IPV6_RECVHOPOPTS39: | |||
1963 | optval = OPTBIT(IN6P_HOPOPTS)(in6p->inp_flags & (0x00040000) ? 1 : 0); | |||
1964 | break; | |||
1965 | ||||
1966 | case IPV6_RECVDSTOPTS40: | |||
1967 | optval = OPTBIT(IN6P_DSTOPTS)(in6p->inp_flags & (0x00080000) ? 1 : 0); | |||
1968 | break; | |||
1969 | ||||
1970 | case IPV6_RECVRTHDRDSTOPTS41: | |||
1971 | optval = OPTBIT(IN6P_RTHDRDSTOPTS)(in6p->inp_flags & (0x00200000) ? 1 : 0); | |||
1972 | break; | |||
1973 | ||||
1974 | case IPV6_UNICAST_HOPS4: | |||
1975 | optval = in6p->in6p_hops; | |||
1976 | break; | |||
1977 | ||||
1978 | case IPV6_RECVPKTINFO36: | |||
1979 | optval = OPTBIT(IN6P_PKTINFO)(in6p->inp_flags & (0x00010000) ? 1 : 0); | |||
1980 | break; | |||
1981 | ||||
1982 | case IPV6_RECVHOPLIMIT37: | |||
1983 | optval = OPTBIT(IN6P_HOPLIMIT)(in6p->inp_flags & (0x00020000) ? 1 : 0); | |||
1984 | break; | |||
1985 | ||||
1986 | case IPV6_RECVRTHDR38: | |||
1987 | optval = OPTBIT(IN6P_RTHDR)(in6p->inp_flags & (0x00100000) ? 1 : 0); | |||
1988 | break; | |||
1989 | ||||
1990 | case IPV6_RECVPATHMTU43: | |||
1991 | optval = OPTBIT(IN6P_MTU)(in6p->inp_flags & (0x80000000) ? 1 : 0); | |||
1992 | break; | |||
1993 | ||||
1994 | case IPV6_V6ONLY27: | |||
1995 | optval = OPTBIT(IN6P_IPV6_V6ONLY)(in6p->inp_flags & (0x00008000) ? 1 : 0); | |||
1996 | break; | |||
1997 | ||||
1998 | case IPV6_PORTRANGE14: | |||
1999 | { | |||
2000 | int flags; | |||
2001 | flags = in6p->inp_flags; | |||
2002 | if (flags & INP_HIGHPORT0x00000010) | |||
2003 | optval = IPV6_PORTRANGE_HIGH1; | |||
2004 | else if (flags & INP_LOWPORT0x00000020) | |||
2005 | optval = IPV6_PORTRANGE_LOW2; | |||
2006 | else | |||
2007 | optval = 0; | |||
2008 | break; | |||
2009 | } | |||
2010 | case IPV6_RECVTCLASS57: | |||
2011 | optval = OPTBIT(IN6P_TCLASS)(in6p->inp_flags & (0x00400000) ? 1 : 0); | |||
2012 | break; | |||
2013 | ||||
2014 | case IPV6_AUTOFLOWLABEL59: | |||
2015 | optval = OPTBIT(IN6P_AUTOFLOWLABEL)(in6p->inp_flags & (0x00800000) ? 1 : 0); | |||
2016 | break; | |||
2017 | ||||
2018 | case IPV6_ORIGDSTADDR72: | |||
2019 | optval = OPTBIT2(INP_ORIGDSTADDR)(in6p->inp_flags2 & (0x00000800) ? 1 : 0); | |||
2020 | break; | |||
2021 | ||||
2022 | case IPV6_BINDANY64: | |||
2023 | optval = OPTBIT(INP_BINDANY)(in6p->inp_flags & (0x00001000) ? 1 : 0); | |||
2024 | break; | |||
2025 | ||||
2026 | case IPV6_FLOWID67: | |||
2027 | optval = in6p->inp_flowid; | |||
2028 | break; | |||
2029 | ||||
2030 | case IPV6_FLOWTYPE68: | |||
2031 | optval = in6p->inp_flowtype; | |||
2032 | break; | |||
2033 | ||||
2034 | case IPV6_RECVFLOWID70: | |||
2035 | optval = OPTBIT2(INP_RECVFLOWID)(in6p->inp_flags2 & (0x00000100) ? 1 : 0); | |||
2036 | break; | |||
2037 | #ifdef RSS | |||
2038 | case IPV6_RSSBUCKETID69: | |||
2039 | retval = | |||
2040 | rss_hash2bucket(in6p->inp_flowid, | |||
2041 | in6p->inp_flowtype, | |||
2042 | &rss_bucket); | |||
2043 | if (retval == 0) | |||
2044 | optval = rss_bucket; | |||
2045 | else | |||
2046 | error = EINVAL22; | |||
2047 | break; | |||
2048 | ||||
2049 | case IPV6_RECVRSSBUCKETID71: | |||
2050 | optval = OPTBIT2(INP_RECVRSSBUCKETID)(in6p->inp_flags2 & (0x00000200) ? 1 : 0); | |||
2051 | break; | |||
2052 | #endif | |||
2053 | ||||
2054 | case IPV6_BINDMULTI65: | |||
2055 | optval = OPTBIT2(INP_BINDMULTI)(in6p->inp_flags2 & (0x00000040) ? 1 : 0); | |||
2056 | break; | |||
2057 | ||||
2058 | } | |||
2059 | if (error) | |||
2060 | break; | |||
2061 | error = sooptcopyout(sopt, &optval, | |||
2062 | sizeof optval); | |||
2063 | break; | |||
2064 | ||||
2065 | case IPV6_PATHMTU44: | |||
2066 | { | |||
2067 | u_long pmtu = 0; | |||
2068 | struct ip6_mtuinfo mtuinfo; | |||
2069 | struct in6_addr addr; | |||
2070 | ||||
2071 | if (!(so->so_state & SS_ISCONNECTED0x0002)) | |||
2072 | return (ENOTCONN57); | |||
2073 | /* | |||
2074 | * XXX: we dot not consider the case of source | |||
2075 | * routing, or optional information to specify | |||
2076 | * the outgoing interface. | |||
2077 | * Copy faddr out of in6p to avoid holding lock | |||
2078 | * on inp during route lookup. | |||
2079 | */ | |||
2080 | INP_RLOCK(in6p)__rw_rlock(&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2080); | |||
2081 | bcopy(&in6p->in6p_faddr, &addr, sizeof(addr))__builtin_memmove((&addr), (&in6p->inp_inc.inc_ie. ie_dependfaddr.id6_addr), (sizeof(addr))); | |||
2082 | INP_RUNLOCK(in6p)_rw_runlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 2082); | |||
2083 | error = ip6_getpmtu_ctl(so->so_fibnum, | |||
2084 | &addr, &pmtu); | |||
2085 | if (error) | |||
2086 | break; | |||
2087 | if (pmtu > IPV6_MAXPACKET65535) | |||
2088 | pmtu = IPV6_MAXPACKET65535; | |||
2089 | ||||
2090 | bzero(&mtuinfo, sizeof(mtuinfo))__builtin_memset((&mtuinfo), 0, (sizeof(mtuinfo))); | |||
2091 | mtuinfo.ip6m_mtu = (u_int32_t)pmtu; | |||
2092 | optdata = (void *)&mtuinfo; | |||
2093 | optdatalen = sizeof(mtuinfo); | |||
2094 | error = sooptcopyout(sopt, optdata, | |||
2095 | optdatalen); | |||
2096 | break; | |||
2097 | } | |||
2098 | ||||
2099 | case IPV6_2292PKTINFO19: | |||
2100 | case IPV6_2292HOPLIMIT20: | |||
2101 | case IPV6_2292HOPOPTS22: | |||
2102 | case IPV6_2292RTHDR24: | |||
2103 | case IPV6_2292DSTOPTS23: | |||
2104 | switch (optname) { | |||
2105 | case IPV6_2292PKTINFO19: | |||
2106 | optval = OPTBIT(IN6P_PKTINFO)(in6p->inp_flags & (0x00010000) ? 1 : 0); | |||
2107 | break; | |||
2108 | case IPV6_2292HOPLIMIT20: | |||
2109 | optval = OPTBIT(IN6P_HOPLIMIT)(in6p->inp_flags & (0x00020000) ? 1 : 0); | |||
2110 | break; | |||
2111 | case IPV6_2292HOPOPTS22: | |||
2112 | optval = OPTBIT(IN6P_HOPOPTS)(in6p->inp_flags & (0x00040000) ? 1 : 0); | |||
2113 | break; | |||
2114 | case IPV6_2292RTHDR24: | |||
2115 | optval = OPTBIT(IN6P_RTHDR)(in6p->inp_flags & (0x00100000) ? 1 : 0); | |||
2116 | break; | |||
2117 | case IPV6_2292DSTOPTS23: | |||
2118 | optval = OPTBIT(IN6P_DSTOPTS|IN6P_RTHDRDSTOPTS)(in6p->inp_flags & (0x00080000|0x00200000) ? 1 : 0); | |||
2119 | break; | |||
2120 | } | |||
2121 | error = sooptcopyout(sopt, &optval, | |||
2122 | sizeof optval); | |||
2123 | break; | |||
2124 | case IPV6_PKTINFO46: | |||
2125 | case IPV6_HOPOPTS49: | |||
2126 | case IPV6_RTHDR51: | |||
2127 | case IPV6_DSTOPTS50: | |||
2128 | case IPV6_RTHDRDSTOPTS35: | |||
2129 | case IPV6_NEXTHOP48: | |||
2130 | case IPV6_TCLASS61: | |||
2131 | case IPV6_DONTFRAG62: | |||
2132 | case IPV6_USE_MIN_MTU42: | |||
2133 | case IPV6_PREFER_TEMPADDR63: | |||
2134 | error = ip6_getpcbopt(in6p, optname, sopt); | |||
2135 | break; | |||
2136 | ||||
2137 | case IPV6_MULTICAST_IF9: | |||
2138 | case IPV6_MULTICAST_HOPS10: | |||
2139 | case IPV6_MULTICAST_LOOP11: | |||
2140 | case IPV6_MSFILTER74: | |||
2141 | error = ip6_getmoptions(in6p, sopt); | |||
2142 | break; | |||
2143 | ||||
2144 | #if defined(IPSEC1) || defined(IPSEC_SUPPORT1) | |||
2145 | case IPV6_IPSEC_POLICY28: | |||
2146 | if (IPSEC_ENABLED(ipv6)((ipv6_ipsec_support)->enabled & 0x0001)) { | |||
2147 | error = IPSEC_PCBCTL(ipv6, in6p, sopt)(*(ipv6_ipsec_support)->methods->pcbctl)(in6p, sopt); | |||
2148 | break; | |||
2149 | } | |||
2150 | /* FALLTHROUGH */ | |||
2151 | #endif /* IPSEC */ | |||
2152 | default: | |||
2153 | error = ENOPROTOOPT42; | |||
2154 | break; | |||
2155 | } | |||
2156 | break; | |||
2157 | } | |||
2158 | } | |||
2159 | return (error); | |||
2160 | } | |||
2161 | ||||
2162 | int | |||
2163 | ip6_raw_ctloutput(struct socket *so, struct sockopt *sopt) | |||
2164 | { | |||
2165 | int error = 0, optval, optlen; | |||
2166 | const int icmp6off = offsetof(struct icmp6_hdr, icmp6_cksum)__builtin_offsetof(struct icmp6_hdr, icmp6_cksum); | |||
2167 | struct inpcb *in6p = sotoinpcb(so)((struct inpcb *)(so)->so_pcb); | |||
2168 | int level, op, optname; | |||
2169 | ||||
2170 | level = sopt->sopt_level; | |||
2171 | op = sopt->sopt_dir; | |||
2172 | optname = sopt->sopt_name; | |||
2173 | optlen = sopt->sopt_valsize; | |||
2174 | ||||
2175 | if (level != IPPROTO_IPV641) { | |||
2176 | return (EINVAL22); | |||
2177 | } | |||
2178 | ||||
2179 | switch (optname) { | |||
2180 | case IPV6_CHECKSUM26: | |||
2181 | /* | |||
2182 | * For ICMPv6 sockets, no modification allowed for checksum | |||
2183 | * offset, permit "no change" values to help existing apps. | |||
2184 | * | |||
2185 | * RFC3542 says: "An attempt to set IPV6_CHECKSUM | |||
2186 | * for an ICMPv6 socket will fail." | |||
2187 | * The current behavior does not meet RFC3542. | |||
2188 | */ | |||
2189 | switch (op) { | |||
2190 | case SOPT_SET: | |||
2191 | if (optlen != sizeof(int)) { | |||
2192 | error = EINVAL22; | |||
2193 | break; | |||
2194 | } | |||
2195 | error = sooptcopyin(sopt, &optval, sizeof(optval), | |||
2196 | sizeof(optval)); | |||
2197 | if (error) | |||
2198 | break; | |||
2199 | if ((optval % 2) != 0) { | |||
2200 | /* the API assumes even offset values */ | |||
2201 | error = EINVAL22; | |||
2202 | } else if (so->so_proto->pr_protocol == | |||
2203 | IPPROTO_ICMPV658) { | |||
2204 | if (optval != icmp6off) | |||
2205 | error = EINVAL22; | |||
2206 | } else | |||
2207 | in6p->in6p_cksum = optval; | |||
2208 | break; | |||
2209 | ||||
2210 | case SOPT_GET: | |||
2211 | if (so->so_proto->pr_protocol == IPPROTO_ICMPV658) | |||
2212 | optval = icmp6off; | |||
2213 | else | |||
2214 | optval = in6p->in6p_cksum; | |||
2215 | ||||
2216 | error = sooptcopyout(sopt, &optval, sizeof(optval)); | |||
2217 | break; | |||
2218 | ||||
2219 | default: | |||
2220 | error = EINVAL22; | |||
2221 | break; | |||
2222 | } | |||
2223 | break; | |||
2224 | ||||
2225 | default: | |||
2226 | error = ENOPROTOOPT42; | |||
2227 | break; | |||
2228 | } | |||
2229 | ||||
2230 | return (error); | |||
2231 | } | |||
2232 | ||||
2233 | /* | |||
2234 | * Set up IP6 options in pcb for insertion in output packets or | |||
2235 | * specifying behavior of outgoing packets. | |||
2236 | */ | |||
2237 | static int | |||
2238 | ip6_pcbopts(struct ip6_pktopts **pktopt, struct mbuf *m, | |||
2239 | struct socket *so, struct sockopt *sopt) | |||
2240 | { | |||
2241 | struct ip6_pktopts *opt = *pktopt; | |||
2242 | int error = 0; | |||
2243 | struct thread *td = sopt->sopt_td; | |||
2244 | ||||
2245 | /* turn off any old options. */ | |||
2246 | if (opt) { | |||
2247 | #ifdef DIAGNOSTIC | |||
2248 | if (opt->ip6po_pktinfo || opt->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop || | |||
2249 | opt->ip6po_hbh || opt->ip6po_dest1 || opt->ip6po_dest2 || | |||
2250 | opt->ip6po_rhinfo.ip6po_rhi_rthdr) | |||
2251 | printf("ip6_pcbopts: all specified options are cleared.\n"); | |||
2252 | #endif | |||
2253 | ip6_clearpktopts(opt, -1); | |||
2254 | } else | |||
2255 | opt = malloc(sizeof(*opt), M_IP6OPT, M_WAITOK0x0002); | |||
2256 | *pktopt = NULL((void *)0); | |||
2257 | ||||
2258 | if (!m || m->m_len == 0) { | |||
2259 | /* | |||
2260 | * Only turning off any previous options, regardless of | |||
2261 | * whether the opt is just created or given. | |||
2262 | */ | |||
2263 | free(opt, M_IP6OPT); | |||
2264 | return (0); | |||
2265 | } | |||
2266 | ||||
2267 | /* set options specified by user. */ | |||
2268 | if ((error = ip6_setpktopts(m, opt, NULL((void *)0), (td != NULL((void *)0)) ? | |||
2269 | td->td_ucred : NULL((void *)0), so->so_proto->pr_protocol)) != 0) { | |||
2270 | ip6_clearpktopts(opt, -1); /* XXX: discard all options */ | |||
2271 | free(opt, M_IP6OPT); | |||
2272 | return (error); | |||
2273 | } | |||
2274 | *pktopt = opt; | |||
2275 | return (0); | |||
2276 | } | |||
2277 | ||||
2278 | /* | |||
2279 | * initialize ip6_pktopts. beware that there are non-zero default values in | |||
2280 | * the struct. | |||
2281 | */ | |||
2282 | void | |||
2283 | ip6_initpktopts(struct ip6_pktopts *opt) | |||
2284 | { | |||
2285 | ||||
2286 | bzero(opt, sizeof(*opt))__builtin_memset((opt), 0, (sizeof(*opt))); | |||
2287 | opt->ip6po_hlim = -1; /* -1 means default hop limit */ | |||
2288 | opt->ip6po_tclass = -1; /* -1 means default traffic class */ | |||
2289 | opt->ip6po_minmtu = IP6PO_MINMTU_MCASTONLY-1; | |||
2290 | opt->ip6po_prefer_tempaddr = IP6PO_TEMPADDR_SYSTEM-1; | |||
2291 | } | |||
2292 | ||||
2293 | static int | |||
2294 | ip6_pcbopt(int optname, u_char *buf, int len, struct ip6_pktopts **pktopt, | |||
2295 | struct ucred *cred, int uproto) | |||
2296 | { | |||
2297 | struct ip6_pktopts *opt; | |||
2298 | ||||
2299 | if (*pktopt == NULL((void *)0)) { | |||
2300 | *pktopt = malloc(sizeof(struct ip6_pktopts), M_IP6OPT, | |||
2301 | M_NOWAIT0x0001); | |||
2302 | if (*pktopt == NULL((void *)0)) | |||
2303 | return (ENOBUFS55); | |||
2304 | ip6_initpktopts(*pktopt); | |||
2305 | } | |||
2306 | opt = *pktopt; | |||
2307 | ||||
2308 | return (ip6_setpktopt(optname, buf, len, opt, cred, 1, 0, uproto)); | |||
2309 | } | |||
2310 | ||||
2311 | #define GET_PKTOPT_VAR(field, lenexpr)do { if (pktopt && pktopt->field) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2311); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2311 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2311); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->field) { optdatalen = min(lenexpr, sopt->sopt_valsize); __builtin_memmove((optdata ), (&pktopt->field), (optdatalen)); } else { free(optdata , M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while (0) do { \ | |||
2312 | if (pktopt && pktopt->field) { \ | |||
2313 | INP_RUNLOCK(in6p)_rw_runlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 2313); \ | |||
2314 | optdata = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK0x0002); \ | |||
2315 | malloc_optdata = true1; \ | |||
2316 | INP_RLOCK(in6p)__rw_rlock(&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2316); \ | |||
2317 | if (in6p->inp_flags & (INP_TIMEWAIT0x01000000 | INP_DROPPED0x04000000)) { \ | |||
2318 | INP_RUNLOCK(in6p)_rw_runlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 2318); \ | |||
2319 | free(optdata, M_TEMP); \ | |||
2320 | return (ECONNRESET54); \ | |||
2321 | } \ | |||
2322 | pktopt = in6p->in6p_outputopts; \ | |||
2323 | if (pktopt && pktopt->field) { \ | |||
2324 | optdatalen = min(lenexpr, sopt->sopt_valsize); \ | |||
2325 | bcopy(&pktopt->field, optdata, optdatalen)__builtin_memmove((optdata), (&pktopt->field), (optdatalen )); \ | |||
2326 | } else { \ | |||
2327 | free(optdata, M_TEMP); \ | |||
2328 | optdata = NULL((void *)0); \ | |||
2329 | malloc_optdata = false0; \ | |||
2330 | } \ | |||
2331 | } \ | |||
2332 | } while(0) | |||
2333 | ||||
2334 | #define GET_PKTOPT_EXT_HDR(field)do { if (pktopt && pktopt->field) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2334); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2334 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2334); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->field) { optdatalen = min((((struct ip6_ext *)pktopt->field)->ip6e_len + 1 ) << 3, sopt->sopt_valsize); __builtin_memmove((optdata ), (&pktopt->field), (optdatalen)); } else { free(optdata , M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while (0) GET_PKTOPT_VAR(field, \do { if (pktopt && pktopt->field) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2335); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2335 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2335); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->field) { optdatalen = min((((struct ip6_ext *)pktopt->field)->ip6e_len + 1 ) << 3, sopt->sopt_valsize); __builtin_memmove((optdata ), (&pktopt->field), (optdatalen)); } else { free(optdata , M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while (0) | |||
2335 | (((struct ip6_ext *)pktopt->field)->ip6e_len + 1) << 3)do { if (pktopt && pktopt->field) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2335); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2335 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2335); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->field) { optdatalen = min((((struct ip6_ext *)pktopt->field)->ip6e_len + 1 ) << 3, sopt->sopt_valsize); __builtin_memmove((optdata ), (&pktopt->field), (optdatalen)); } else { free(optdata , M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while (0) | |||
2336 | ||||
2337 | #define GET_PKTOPT_SOCKADDR(field)do { if (pktopt && pktopt->field) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2337); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2337 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2337); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->field) { optdatalen = min(pktopt->field->sa_len, sopt->sopt_valsize); __builtin_memmove ((optdata), (&pktopt->field), (optdatalen)); } else { free (optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0) GET_PKTOPT_VAR(field, \do { if (pktopt && pktopt->field) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2338); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2338 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2338); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->field) { optdatalen = min(pktopt->field->sa_len, sopt->sopt_valsize); __builtin_memmove ((optdata), (&pktopt->field), (optdatalen)); } else { free (optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0) | |||
2338 | pktopt->field->sa_len)do { if (pktopt && pktopt->field) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2338); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2338 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2338); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->field) { optdatalen = min(pktopt->field->sa_len, sopt->sopt_valsize); __builtin_memmove ((optdata), (&pktopt->field), (optdatalen)); } else { free (optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0) | |||
2339 | ||||
2340 | static int | |||
2341 | ip6_getpcbopt(struct inpcb *in6p, int optname, struct sockopt *sopt) | |||
2342 | { | |||
2343 | void *optdata = NULL((void *)0); | |||
2344 | bool malloc_optdata = false0; | |||
2345 | int optdatalen = 0; | |||
2346 | int error = 0; | |||
2347 | struct in6_pktinfo null_pktinfo; | |||
2348 | int deftclass = 0, on; | |||
2349 | int defminmtu = IP6PO_MINMTU_MCASTONLY-1; | |||
2350 | int defpreftemp = IP6PO_TEMPADDR_SYSTEM-1; | |||
2351 | struct ip6_pktopts *pktopt; | |||
2352 | ||||
2353 | INP_RLOCK(in6p)__rw_rlock(&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2353); | |||
2354 | pktopt = in6p->in6p_outputopts; | |||
2355 | ||||
2356 | switch (optname) { | |||
2357 | case IPV6_PKTINFO46: | |||
2358 | optdata = (void *)&null_pktinfo; | |||
2359 | if (pktopt && pktopt->ip6po_pktinfo) { | |||
2360 | bcopy(pktopt->ip6po_pktinfo, &null_pktinfo,__builtin_memmove((&null_pktinfo), (pktopt->ip6po_pktinfo ), (sizeof(null_pktinfo))) | |||
2361 | sizeof(null_pktinfo))__builtin_memmove((&null_pktinfo), (pktopt->ip6po_pktinfo ), (sizeof(null_pktinfo))); | |||
2362 | in6_clearscope(&null_pktinfo.ipi6_addr); | |||
2363 | } else { | |||
2364 | /* XXX: we don't have to do this every time... */ | |||
2365 | bzero(&null_pktinfo, sizeof(null_pktinfo))__builtin_memset((&null_pktinfo), 0, (sizeof(null_pktinfo ))); | |||
2366 | } | |||
2367 | optdatalen = sizeof(struct in6_pktinfo); | |||
2368 | break; | |||
2369 | case IPV6_TCLASS61: | |||
2370 | if (pktopt && pktopt->ip6po_tclass >= 0) | |||
2371 | deftclass = pktopt->ip6po_tclass; | |||
2372 | optdata = (void *)&deftclass; | |||
2373 | optdatalen = sizeof(int); | |||
2374 | break; | |||
2375 | case IPV6_HOPOPTS49: | |||
2376 | GET_PKTOPT_EXT_HDR(ip6po_hbh)do { if (pktopt && pktopt->ip6po_hbh) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2376); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2376 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2376); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->ip6po_hbh) { optdatalen = min((((struct ip6_ext *)pktopt->ip6po_hbh)-> ip6e_len + 1) << 3, sopt->sopt_valsize); __builtin_memmove ((optdata), (&pktopt->ip6po_hbh), (optdatalen)); } else { free(optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0); | |||
2377 | break; | |||
2378 | case IPV6_RTHDR51: | |||
2379 | GET_PKTOPT_EXT_HDR(ip6po_rthdr)do { if (pktopt && pktopt->ip6po_rhinfo.ip6po_rhi_rthdr ) { _rw_runlock_cookie(&((&(in6p)->inp_lock))-> rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2379); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 2379); if (in6p-> inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2379); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->ip6po_rhinfo .ip6po_rhi_rthdr) { optdatalen = min((((struct ip6_ext *)pktopt ->ip6po_rhinfo.ip6po_rhi_rthdr)->ip6e_len + 1) << 3, sopt->sopt_valsize); __builtin_memmove((optdata), (& pktopt->ip6po_rhinfo.ip6po_rhi_rthdr), (optdatalen)); } else { free(optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0); | |||
2380 | break; | |||
2381 | case IPV6_RTHDRDSTOPTS35: | |||
2382 | GET_PKTOPT_EXT_HDR(ip6po_dest1)do { if (pktopt && pktopt->ip6po_dest1) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2382); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2382 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2382); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->ip6po_dest1 ) { optdatalen = min((((struct ip6_ext *)pktopt->ip6po_dest1 )->ip6e_len + 1) << 3, sopt->sopt_valsize); __builtin_memmove ((optdata), (&pktopt->ip6po_dest1), (optdatalen)); } else { free(optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0); | |||
2383 | break; | |||
2384 | case IPV6_DSTOPTS50: | |||
2385 | GET_PKTOPT_EXT_HDR(ip6po_dest2)do { if (pktopt && pktopt->ip6po_dest2) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2385); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002 ); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock ))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2385 ); if (in6p->inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2385); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->ip6po_dest2 ) { optdatalen = min((((struct ip6_ext *)pktopt->ip6po_dest2 )->ip6e_len + 1) << 3, sopt->sopt_valsize); __builtin_memmove ((optdata), (&pktopt->ip6po_dest2), (optdatalen)); } else { free(optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0); | |||
2386 | break; | |||
2387 | case IPV6_NEXTHOP48: | |||
2388 | GET_PKTOPT_SOCKADDR(ip6po_nexthop)do { if (pktopt && pktopt->ip6po_nhinfo.ip6po_nhi_nexthop ) { _rw_runlock_cookie(&((&(in6p)->inp_lock))-> rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c", 2388); optdata = malloc(sopt->sopt_valsize, M_TEMP, 0x0002); malloc_optdata = 1; __rw_rlock(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 2388); if (in6p-> inp_flags & (0x01000000 | 0x04000000)) { _rw_runlock_cookie (&((&(in6p)->inp_lock))->rw_lock, "/root/freebsd/sys/netinet6/ip6_output.c" , 2388); free(optdata, M_TEMP); return (54); } pktopt = in6p-> in6p_outputopts; if (pktopt && pktopt->ip6po_nhinfo .ip6po_nhi_nexthop) { optdatalen = min(pktopt->ip6po_nhinfo .ip6po_nhi_nexthop->sa_len, sopt->sopt_valsize); __builtin_memmove ((optdata), (&pktopt->ip6po_nhinfo.ip6po_nhi_nexthop), (optdatalen)); } else { free(optdata, M_TEMP); optdata = ((void *)0); malloc_optdata = 0; } } } while(0); | |||
2389 | break; | |||
2390 | case IPV6_USE_MIN_MTU42: | |||
2391 | if (pktopt) | |||
2392 | defminmtu = pktopt->ip6po_minmtu; | |||
2393 | optdata = (void *)&defminmtu; | |||
2394 | optdatalen = sizeof(int); | |||
2395 | break; | |||
2396 | case IPV6_DONTFRAG62: | |||
2397 | if (pktopt && ((pktopt->ip6po_flags) & IP6PO_DONTFRAG0x04)) | |||
2398 | on = 1; | |||
2399 | else | |||
2400 | on = 0; | |||
2401 | optdata = (void *)&on; | |||
2402 | optdatalen = sizeof(on); | |||
2403 | break; | |||
2404 | case IPV6_PREFER_TEMPADDR63: | |||
2405 | if (pktopt) | |||
2406 | defpreftemp = pktopt->ip6po_prefer_tempaddr; | |||
2407 | optdata = (void *)&defpreftemp; | |||
2408 | optdatalen = sizeof(int); | |||
2409 | break; | |||
2410 | default: /* should not happen */ | |||
2411 | #ifdef DIAGNOSTIC | |||
2412 | panic("ip6_getpcbopt: unexpected option\n"); | |||
2413 | #endif | |||
2414 | INP_RUNLOCK(in6p)_rw_runlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 2414); | |||
2415 | return (ENOPROTOOPT42); | |||
2416 | } | |||
2417 | INP_RUNLOCK(in6p)_rw_runlock_cookie(&((&(in6p)->inp_lock))->rw_lock , "/root/freebsd/sys/netinet6/ip6_output.c", 2417); | |||
2418 | ||||
2419 | error = sooptcopyout(sopt, optdata, optdatalen); | |||
| ||||
2420 | if (malloc_optdata) | |||
2421 | free(optdata, M_TEMP); | |||
2422 | ||||
2423 | return (error); | |||
2424 | } | |||
2425 | ||||
2426 | void | |||
2427 | ip6_clearpktopts(struct ip6_pktopts *pktopt, int optname) | |||
2428 | { | |||
2429 | if (pktopt == NULL((void *)0)) | |||
2430 | return; | |||
2431 | ||||
2432 | if (optname == -1 || optname == IPV6_PKTINFO46) { | |||
2433 | if (pktopt->ip6po_pktinfo) | |||
2434 | free(pktopt->ip6po_pktinfo, M_IP6OPT); | |||
2435 | pktopt->ip6po_pktinfo = NULL((void *)0); | |||
2436 | } | |||
2437 | if (optname == -1 || optname == IPV6_HOPLIMIT47) | |||
2438 | pktopt->ip6po_hlim = -1; | |||
2439 | if (optname == -1 || optname == IPV6_TCLASS61) | |||
2440 | pktopt->ip6po_tclass = -1; | |||
2441 | if (optname == -1 || optname == IPV6_NEXTHOP48) { | |||
2442 | if (pktopt->ip6po_nextrouteip6po_nhinfo.ip6po_nhi_route.ro_rt) { | |||
2443 | RTFREE(pktopt->ip6po_nextroute.ro_rt)do { __mtx_lock_flags(&((((&(pktopt->ip6po_nhinfo. ip6po_nhi_route.ro_rt)->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (2443)); do { if ((pktopt->ip6po_nhinfo.ip6po_nhi_route .ro_rt)->rt_refcnt <= 1) rtfree(pktopt->ip6po_nhinfo .ip6po_nhi_route.ro_rt); else { do { __mtx_assert(&(((& (pktopt->ip6po_nhinfo.ip6po_nhi_route.ro_rt)->rt_mtx))) ->mtx_lock, ((0x00000004)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (2443)); do { if (__builtin_expect((!((pktopt->ip6po_nhinfo .ip6po_nhi_route.ro_rt)->rt_refcnt > 0)), 0)) panic ("bogus refcnt %d" , (pktopt->ip6po_nhinfo.ip6po_nhi_route.ro_rt)->rt_refcnt ); } while (0); (pktopt->ip6po_nhinfo.ip6po_nhi_route.ro_rt )->rt_refcnt--; } while (0); __mtx_unlock_flags(&((((& (pktopt->ip6po_nhinfo.ip6po_nhi_route.ro_rt)->rt_mtx))) )->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (2443)); } pktopt->ip6po_nhinfo.ip6po_nhi_route.ro_rt = 0; } while (0); } while (0); | |||
2444 | pktopt->ip6po_nextrouteip6po_nhinfo.ip6po_nhi_route.ro_rt = NULL((void *)0); | |||
2445 | } | |||
2446 | if (pktopt->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop) | |||
2447 | free(pktopt->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop, M_IP6OPT); | |||
2448 | pktopt->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop = NULL((void *)0); | |||
2449 | } | |||
2450 | if (optname == -1 || optname == IPV6_HOPOPTS49) { | |||
2451 | if (pktopt->ip6po_hbh) | |||
2452 | free(pktopt->ip6po_hbh, M_IP6OPT); | |||
2453 | pktopt->ip6po_hbh = NULL((void *)0); | |||
2454 | } | |||
2455 | if (optname == -1 || optname == IPV6_RTHDRDSTOPTS35) { | |||
2456 | if (pktopt->ip6po_dest1) | |||
2457 | free(pktopt->ip6po_dest1, M_IP6OPT); | |||
2458 | pktopt->ip6po_dest1 = NULL((void *)0); | |||
2459 | } | |||
2460 | if (optname == -1 || optname == IPV6_RTHDR51) { | |||
2461 | if (pktopt->ip6po_rhinfo.ip6po_rhi_rthdr) | |||
2462 | free(pktopt->ip6po_rhinfo.ip6po_rhi_rthdr, M_IP6OPT); | |||
2463 | pktopt->ip6po_rhinfo.ip6po_rhi_rthdr = NULL((void *)0); | |||
2464 | if (pktopt->ip6po_routeip6po_rhinfo.ip6po_rhi_route.ro_rt) { | |||
2465 | RTFREE(pktopt->ip6po_route.ro_rt)do { __mtx_lock_flags(&((((&(pktopt->ip6po_rhinfo. ip6po_rhi_route.ro_rt)->rt_mtx))))->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (2465)); do { if ((pktopt->ip6po_rhinfo.ip6po_rhi_route .ro_rt)->rt_refcnt <= 1) rtfree(pktopt->ip6po_rhinfo .ip6po_rhi_route.ro_rt); else { do { __mtx_assert(&(((& (pktopt->ip6po_rhinfo.ip6po_rhi_route.ro_rt)->rt_mtx))) ->mtx_lock, ((0x00000004)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (2465)); do { if (__builtin_expect((!((pktopt->ip6po_rhinfo .ip6po_rhi_route.ro_rt)->rt_refcnt > 0)), 0)) panic ("bogus refcnt %d" , (pktopt->ip6po_rhinfo.ip6po_rhi_route.ro_rt)->rt_refcnt ); } while (0); (pktopt->ip6po_rhinfo.ip6po_rhi_route.ro_rt )->rt_refcnt--; } while (0); __mtx_unlock_flags(&((((& (pktopt->ip6po_rhinfo.ip6po_rhi_route.ro_rt)->rt_mtx))) )->mtx_lock, ((0)), ("/root/freebsd/sys/netinet6/ip6_output.c" ), (2465)); } pktopt->ip6po_rhinfo.ip6po_rhi_route.ro_rt = 0; } while (0); } while (0); | |||
2466 | pktopt->ip6po_routeip6po_rhinfo.ip6po_rhi_route.ro_rt = NULL((void *)0); | |||
2467 | } | |||
2468 | } | |||
2469 | if (optname == -1 || optname == IPV6_DSTOPTS50) { | |||
2470 | if (pktopt->ip6po_dest2) | |||
2471 | free(pktopt->ip6po_dest2, M_IP6OPT); | |||
2472 | pktopt->ip6po_dest2 = NULL((void *)0); | |||
2473 | } | |||
2474 | } | |||
2475 | ||||
2476 | #define PKTOPT_EXTHDRCPY(type) \ | |||
2477 | do {\ | |||
2478 | if (src->type) {\ | |||
2479 | int hlen = (((struct ip6_ext *)src->type)->ip6e_len + 1) << 3;\ | |||
2480 | dst->type = malloc(hlen, M_IP6OPT, canwait);\ | |||
2481 | if (dst->type == NULL((void *)0))\ | |||
2482 | goto bad;\ | |||
2483 | bcopy(src->type, dst->type, hlen)__builtin_memmove((dst->type), (src->type), (hlen));\ | |||
2484 | }\ | |||
2485 | } while (/*CONSTCOND*/ 0) | |||
2486 | ||||
2487 | static int | |||
2488 | copypktopts(struct ip6_pktopts *dst, struct ip6_pktopts *src, int canwait) | |||
2489 | { | |||
2490 | if (dst == NULL((void *)0) || src == NULL((void *)0)) { | |||
2491 | printf("ip6_clearpktopts: invalid argument\n"); | |||
2492 | return (EINVAL22); | |||
2493 | } | |||
2494 | ||||
2495 | dst->ip6po_hlim = src->ip6po_hlim; | |||
2496 | dst->ip6po_tclass = src->ip6po_tclass; | |||
2497 | dst->ip6po_flags = src->ip6po_flags; | |||
2498 | dst->ip6po_minmtu = src->ip6po_minmtu; | |||
2499 | dst->ip6po_prefer_tempaddr = src->ip6po_prefer_tempaddr; | |||
2500 | if (src->ip6po_pktinfo) { | |||
2501 | dst->ip6po_pktinfo = malloc(sizeof(*dst->ip6po_pktinfo), | |||
2502 | M_IP6OPT, canwait); | |||
2503 | if (dst->ip6po_pktinfo == NULL((void *)0)) | |||
2504 | goto bad; | |||
2505 | *dst->ip6po_pktinfo = *src->ip6po_pktinfo; | |||
2506 | } | |||
2507 | if (src->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop) { | |||
2508 | dst->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop = malloc(src->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop->sa_len, | |||
2509 | M_IP6OPT, canwait); | |||
2510 | if (dst->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop == NULL((void *)0)) | |||
2511 | goto bad; | |||
2512 | bcopy(src->ip6po_nexthop, dst->ip6po_nexthop,__builtin_memmove((dst->ip6po_nhinfo.ip6po_nhi_nexthop), ( src->ip6po_nhinfo.ip6po_nhi_nexthop), (src->ip6po_nhinfo .ip6po_nhi_nexthop->sa_len)) | |||
2513 | src->ip6po_nexthop->sa_len)__builtin_memmove((dst->ip6po_nhinfo.ip6po_nhi_nexthop), ( src->ip6po_nhinfo.ip6po_nhi_nexthop), (src->ip6po_nhinfo .ip6po_nhi_nexthop->sa_len)); | |||
2514 | } | |||
2515 | PKTOPT_EXTHDRCPY(ip6po_hbh); | |||
2516 | PKTOPT_EXTHDRCPY(ip6po_dest1); | |||
2517 | PKTOPT_EXTHDRCPY(ip6po_dest2); | |||
2518 | PKTOPT_EXTHDRCPY(ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr); /* not copy the cached route */ | |||
2519 | return (0); | |||
2520 | ||||
2521 | bad: | |||
2522 | ip6_clearpktopts(dst, -1); | |||
2523 | return (ENOBUFS55); | |||
2524 | } | |||
2525 | #undef PKTOPT_EXTHDRCPY | |||
2526 | ||||
2527 | struct ip6_pktopts * | |||
2528 | ip6_copypktopts(struct ip6_pktopts *src, int canwait) | |||
2529 | { | |||
2530 | int error; | |||
2531 | struct ip6_pktopts *dst; | |||
2532 | ||||
2533 | dst = malloc(sizeof(*dst), M_IP6OPT, canwait); | |||
2534 | if (dst == NULL((void *)0)) | |||
2535 | return (NULL((void *)0)); | |||
2536 | ip6_initpktopts(dst); | |||
2537 | ||||
2538 | if ((error = copypktopts(dst, src, canwait)) != 0) { | |||
2539 | free(dst, M_IP6OPT); | |||
2540 | return (NULL((void *)0)); | |||
2541 | } | |||
2542 | ||||
2543 | return (dst); | |||
2544 | } | |||
2545 | ||||
2546 | void | |||
2547 | ip6_freepcbopts(struct ip6_pktopts *pktopt) | |||
2548 | { | |||
2549 | if (pktopt == NULL((void *)0)) | |||
2550 | return; | |||
2551 | ||||
2552 | ip6_clearpktopts(pktopt, -1); | |||
2553 | ||||
2554 | free(pktopt, M_IP6OPT); | |||
2555 | } | |||
2556 | ||||
2557 | /* | |||
2558 | * Set IPv6 outgoing packet options based on advanced API. | |||
2559 | */ | |||
2560 | int | |||
2561 | ip6_setpktopts(struct mbuf *control, struct ip6_pktopts *opt, | |||
2562 | struct ip6_pktopts *stickyopt, struct ucred *cred, int uproto) | |||
2563 | { | |||
2564 | struct cmsghdr *cm = NULL((void *)0); | |||
2565 | ||||
2566 | if (control == NULL((void *)0) || opt == NULL((void *)0)) | |||
2567 | return (EINVAL22); | |||
2568 | ||||
2569 | ip6_initpktopts(opt); | |||
2570 | if (stickyopt) { | |||
2571 | int error; | |||
2572 | ||||
2573 | /* | |||
2574 | * If stickyopt is provided, make a local copy of the options | |||
2575 | * for this particular packet, then override them by ancillary | |||
2576 | * objects. | |||
2577 | * XXX: copypktopts() does not copy the cached route to a next | |||
2578 | * hop (if any). This is not very good in terms of efficiency, | |||
2579 | * but we can allow this since this option should be rarely | |||
2580 | * used. | |||
2581 | */ | |||
2582 | if ((error = copypktopts(opt, stickyopt, M_NOWAIT0x0001)) != 0) | |||
2583 | return (error); | |||
2584 | } | |||
2585 | ||||
2586 | /* | |||
2587 | * XXX: Currently, we assume all the optional information is stored | |||
2588 | * in a single mbuf. | |||
2589 | */ | |||
2590 | if (control->m_next) | |||
2591 | return (EINVAL22); | |||
2592 | ||||
2593 | for (; control->m_len > 0; control->m_data += CMSG_ALIGN(cm->cmsg_len)(((__uintptr_t)(cm->cmsg_len) + (sizeof(__register_t) - 1) ) & ~(sizeof(__register_t) - 1)), | |||
2594 | control->m_len -= CMSG_ALIGN(cm->cmsg_len)(((__uintptr_t)(cm->cmsg_len) + (sizeof(__register_t) - 1) ) & ~(sizeof(__register_t) - 1))) { | |||
2595 | int error; | |||
2596 | ||||
2597 | if (control->m_len < CMSG_LEN(0)((((__uintptr_t)(sizeof(struct cmsghdr)) + (sizeof(__register_t ) - 1)) & ~(sizeof(__register_t) - 1)) + (0))) | |||
2598 | return (EINVAL22); | |||
2599 | ||||
2600 | cm = mtod(control, struct cmsghdr *)((struct cmsghdr *)((control)->m_data)); | |||
2601 | if (cm->cmsg_len == 0 || cm->cmsg_len > control->m_len) | |||
2602 | return (EINVAL22); | |||
2603 | if (cm->cmsg_level != IPPROTO_IPV641) | |||
2604 | continue; | |||
2605 | ||||
2606 | error = ip6_setpktopt(cm->cmsg_type, CMSG_DATA(cm)((unsigned char *)(cm) + (((__uintptr_t)(sizeof(struct cmsghdr )) + (sizeof(__register_t) - 1)) & ~(sizeof(__register_t) - 1))), | |||
2607 | cm->cmsg_len - CMSG_LEN(0)((((__uintptr_t)(sizeof(struct cmsghdr)) + (sizeof(__register_t ) - 1)) & ~(sizeof(__register_t) - 1)) + (0)), opt, cred, 0, 1, uproto); | |||
2608 | if (error) | |||
2609 | return (error); | |||
2610 | } | |||
2611 | ||||
2612 | return (0); | |||
2613 | } | |||
2614 | ||||
2615 | /* | |||
2616 | * Set a particular packet option, as a sticky option or an ancillary data | |||
2617 | * item. "len" can be 0 only when it's a sticky option. | |||
2618 | * We have 4 cases of combination of "sticky" and "cmsg": | |||
2619 | * "sticky=0, cmsg=0": impossible | |||
2620 | * "sticky=0, cmsg=1": RFC2292 or RFC3542 ancillary data | |||
2621 | * "sticky=1, cmsg=0": RFC3542 socket option | |||
2622 | * "sticky=1, cmsg=1": RFC2292 socket option | |||
2623 | */ | |||
2624 | static int | |||
2625 | ip6_setpktopt(int optname, u_char *buf, int len, struct ip6_pktopts *opt, | |||
2626 | struct ucred *cred, int sticky, int cmsg, int uproto) | |||
2627 | { | |||
2628 | int minmtupolicy, preftemp; | |||
2629 | int error; | |||
2630 | ||||
2631 | if (!sticky && !cmsg) { | |||
2632 | #ifdef DIAGNOSTIC | |||
2633 | printf("ip6_setpktopt: impossible case\n"); | |||
2634 | #endif | |||
2635 | return (EINVAL22); | |||
2636 | } | |||
2637 | ||||
2638 | /* | |||
2639 | * IPV6_2292xxx is for backward compatibility to RFC2292, and should | |||
2640 | * not be specified in the context of RFC3542. Conversely, | |||
2641 | * RFC3542 types should not be specified in the context of RFC2292. | |||
2642 | */ | |||
2643 | if (!cmsg) { | |||
2644 | switch (optname) { | |||
2645 | case IPV6_2292PKTINFO19: | |||
2646 | case IPV6_2292HOPLIMIT20: | |||
2647 | case IPV6_2292NEXTHOP21: | |||
2648 | case IPV6_2292HOPOPTS22: | |||
2649 | case IPV6_2292DSTOPTS23: | |||
2650 | case IPV6_2292RTHDR24: | |||
2651 | case IPV6_2292PKTOPTIONS25: | |||
2652 | return (ENOPROTOOPT42); | |||
2653 | } | |||
2654 | } | |||
2655 | if (sticky && cmsg) { | |||
2656 | switch (optname) { | |||
2657 | case IPV6_PKTINFO46: | |||
2658 | case IPV6_HOPLIMIT47: | |||
2659 | case IPV6_NEXTHOP48: | |||
2660 | case IPV6_HOPOPTS49: | |||
2661 | case IPV6_DSTOPTS50: | |||
2662 | case IPV6_RTHDRDSTOPTS35: | |||
2663 | case IPV6_RTHDR51: | |||
2664 | case IPV6_USE_MIN_MTU42: | |||
2665 | case IPV6_DONTFRAG62: | |||
2666 | case IPV6_TCLASS61: | |||
2667 | case IPV6_PREFER_TEMPADDR63: /* XXX: not an RFC3542 option */ | |||
2668 | return (ENOPROTOOPT42); | |||
2669 | } | |||
2670 | } | |||
2671 | ||||
2672 | switch (optname) { | |||
2673 | case IPV6_2292PKTINFO19: | |||
2674 | case IPV6_PKTINFO46: | |||
2675 | { | |||
2676 | struct ifnet *ifp = NULL((void *)0); | |||
2677 | struct in6_pktinfo *pktinfo; | |||
2678 | ||||
2679 | if (len != sizeof(struct in6_pktinfo)) | |||
2680 | return (EINVAL22); | |||
2681 | ||||
2682 | pktinfo = (struct in6_pktinfo *)buf; | |||
2683 | ||||
2684 | /* | |||
2685 | * An application can clear any sticky IPV6_PKTINFO option by | |||
2686 | * doing a "regular" setsockopt with ipi6_addr being | |||
2687 | * in6addr_any and ipi6_ifindex being zero. | |||
2688 | * [RFC 3542, Section 6] | |||
2689 | */ | |||
2690 | if (optname == IPV6_PKTINFO46 && opt->ip6po_pktinfo && | |||
2691 | pktinfo->ipi6_ifindex == 0 && | |||
2692 | IN6_IS_ADDR_UNSPECIFIED(&pktinfo->ipi6_addr)((&pktinfo->ipi6_addr)->__u6_addr.__u6_addr32[0] == 0 && (&pktinfo->ipi6_addr)->__u6_addr.__u6_addr32 [1] == 0 && (&pktinfo->ipi6_addr)->__u6_addr .__u6_addr32[2] == 0 && (&pktinfo->ipi6_addr)-> __u6_addr.__u6_addr32[3] == 0)) { | |||
2693 | ip6_clearpktopts(opt, optname); | |||
2694 | break; | |||
2695 | } | |||
2696 | ||||
2697 | if (uproto == IPPROTO_TCP6 && optname == IPV6_PKTINFO46 && | |||
2698 | sticky && !IN6_IS_ADDR_UNSPECIFIED(&pktinfo->ipi6_addr)((&pktinfo->ipi6_addr)->__u6_addr.__u6_addr32[0] == 0 && (&pktinfo->ipi6_addr)->__u6_addr.__u6_addr32 [1] == 0 && (&pktinfo->ipi6_addr)->__u6_addr .__u6_addr32[2] == 0 && (&pktinfo->ipi6_addr)-> __u6_addr.__u6_addr32[3] == 0)) { | |||
2699 | return (EINVAL22); | |||
2700 | } | |||
2701 | if (IN6_IS_ADDR_MULTICAST(&pktinfo->ipi6_addr)((&pktinfo->ipi6_addr)->__u6_addr.__u6_addr8[0] == 0xff )) | |||
2702 | return (EINVAL22); | |||
2703 | /* validate the interface index if specified. */ | |||
2704 | if (pktinfo->ipi6_ifindex > V_if_index(*(__typeof(vnet_entry_if_index)*) (((((__curthread())->td_vnet ))->vnet_data_base) + (uintptr_t)&vnet_entry_if_index) )) | |||
2705 | return (ENXIO6); | |||
2706 | if (pktinfo->ipi6_ifindex) { | |||
2707 | ifp = ifnet_byindex(pktinfo->ipi6_ifindex); | |||
2708 | if (ifp == NULL((void *)0)) | |||
2709 | return (ENXIO6); | |||
2710 | } | |||
2711 | if (ifp != NULL((void *)0) && (ifp->if_afdata[AF_INET628] == NULL((void *)0) || | |||
2712 | (ND_IFINFO(ifp)(((struct in6_ifextra *)(ifp)->if_afdata[28])->nd_ifinfo )->flags & ND6_IFF_IFDISABLED0x8) != 0)) | |||
2713 | return (ENETDOWN50); | |||
2714 | ||||
2715 | if (ifp != NULL((void *)0) && | |||
2716 | !IN6_IS_ADDR_UNSPECIFIED(&pktinfo->ipi6_addr)((&pktinfo->ipi6_addr)->__u6_addr.__u6_addr32[0] == 0 && (&pktinfo->ipi6_addr)->__u6_addr.__u6_addr32 [1] == 0 && (&pktinfo->ipi6_addr)->__u6_addr .__u6_addr32[2] == 0 && (&pktinfo->ipi6_addr)-> __u6_addr.__u6_addr32[3] == 0)) { | |||
2717 | struct in6_ifaddr *ia; | |||
2718 | ||||
2719 | in6_setscope(&pktinfo->ipi6_addr, ifp, NULL((void *)0)); | |||
2720 | ia = in6ifa_ifpwithaddr(ifp, &pktinfo->ipi6_addr); | |||
2721 | if (ia == NULL((void *)0)) | |||
2722 | return (EADDRNOTAVAIL49); | |||
2723 | ifa_free(&ia->ia_ifa); | |||
2724 | } | |||
2725 | /* | |||
2726 | * We store the address anyway, and let in6_selectsrc() | |||
2727 | * validate the specified address. This is because ipi6_addr | |||
2728 | * may not have enough information about its scope zone, and | |||
2729 | * we may need additional information (such as outgoing | |||
2730 | * interface or the scope zone of a destination address) to | |||
2731 | * disambiguate the scope. | |||
2732 | * XXX: the delay of the validation may confuse the | |||
2733 | * application when it is used as a sticky option. | |||
2734 | */ | |||
2735 | if (opt->ip6po_pktinfo == NULL((void *)0)) { | |||
2736 | opt->ip6po_pktinfo = malloc(sizeof(*pktinfo), | |||
2737 | M_IP6OPT, M_NOWAIT0x0001); | |||
2738 | if (opt->ip6po_pktinfo == NULL((void *)0)) | |||
2739 | return (ENOBUFS55); | |||
2740 | } | |||
2741 | bcopy(pktinfo, opt->ip6po_pktinfo, sizeof(*pktinfo))__builtin_memmove((opt->ip6po_pktinfo), (pktinfo), (sizeof (*pktinfo))); | |||
2742 | break; | |||
2743 | } | |||
2744 | ||||
2745 | case IPV6_2292HOPLIMIT20: | |||
2746 | case IPV6_HOPLIMIT47: | |||
2747 | { | |||
2748 | int *hlimp; | |||
2749 | ||||
2750 | /* | |||
2751 | * RFC 3542 deprecated the usage of sticky IPV6_HOPLIMIT | |||
2752 | * to simplify the ordering among hoplimit options. | |||
2753 | */ | |||
2754 | if (optname == IPV6_HOPLIMIT47 && sticky) | |||
2755 | return (ENOPROTOOPT42); | |||
2756 | ||||
2757 | if (len != sizeof(int)) | |||
2758 | return (EINVAL22); | |||
2759 | hlimp = (int *)buf; | |||
2760 | if (*hlimp < -1 || *hlimp > 255) | |||
2761 | return (EINVAL22); | |||
2762 | ||||
2763 | opt->ip6po_hlim = *hlimp; | |||
2764 | break; | |||
2765 | } | |||
2766 | ||||
2767 | case IPV6_TCLASS61: | |||
2768 | { | |||
2769 | int tclass; | |||
2770 | ||||
2771 | if (len != sizeof(int)) | |||
2772 | return (EINVAL22); | |||
2773 | tclass = *(int *)buf; | |||
2774 | if (tclass < -1 || tclass > 255) | |||
2775 | return (EINVAL22); | |||
2776 | ||||
2777 | opt->ip6po_tclass = tclass; | |||
2778 | break; | |||
2779 | } | |||
2780 | ||||
2781 | case IPV6_2292NEXTHOP21: | |||
2782 | case IPV6_NEXTHOP48: | |||
2783 | if (cred != NULL((void *)0)) { | |||
2784 | error = priv_check_cred(cred, PRIV_NETINET_SETHDROPTS505); | |||
2785 | if (error) | |||
2786 | return (error); | |||
2787 | } | |||
2788 | ||||
2789 | if (len == 0) { /* just remove the option */ | |||
2790 | ip6_clearpktopts(opt, IPV6_NEXTHOP48); | |||
2791 | break; | |||
2792 | } | |||
2793 | ||||
2794 | /* check if cmsg_len is large enough for sa_len */ | |||
2795 | if (len < sizeof(struct sockaddr) || len < *buf) | |||
2796 | return (EINVAL22); | |||
2797 | ||||
2798 | switch (((struct sockaddr *)buf)->sa_family) { | |||
2799 | case AF_INET628: | |||
2800 | { | |||
2801 | struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)buf; | |||
2802 | int error; | |||
2803 | ||||
2804 | if (sa6->sin6_len != sizeof(struct sockaddr_in6)) | |||
2805 | return (EINVAL22); | |||
2806 | ||||
2807 | if (IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr)((&sa6->sin6_addr)->__u6_addr.__u6_addr32[0] == 0 && (&sa6->sin6_addr)->__u6_addr.__u6_addr32[1] == 0 && (&sa6->sin6_addr)->__u6_addr.__u6_addr32[2] == 0 && (&sa6->sin6_addr)->__u6_addr.__u6_addr32[3] == 0) || | |||
2808 | IN6_IS_ADDR_MULTICAST(&sa6->sin6_addr)((&sa6->sin6_addr)->__u6_addr.__u6_addr8[0] == 0xff )) { | |||
2809 | return (EINVAL22); | |||
2810 | } | |||
2811 | if ((error = sa6_embedscope(sa6, V_ip6_use_defzone(*(__typeof(vnet_entry_ip6_use_defzone)*) (((((__curthread()) ->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ip6_use_defzone )))) | |||
2812 | != 0) { | |||
2813 | return (error); | |||
2814 | } | |||
2815 | break; | |||
2816 | } | |||
2817 | case AF_LINK18: /* should eventually be supported */ | |||
2818 | default: | |||
2819 | return (EAFNOSUPPORT47); | |||
2820 | } | |||
2821 | ||||
2822 | /* turn off the previous option, then set the new option. */ | |||
2823 | ip6_clearpktopts(opt, IPV6_NEXTHOP48); | |||
2824 | opt->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop = malloc(*buf, M_IP6OPT, M_NOWAIT0x0001); | |||
2825 | if (opt->ip6po_nexthopip6po_nhinfo.ip6po_nhi_nexthop == NULL((void *)0)) | |||
2826 | return (ENOBUFS55); | |||
2827 | bcopy(buf, opt->ip6po_nexthop, *buf)__builtin_memmove((opt->ip6po_nhinfo.ip6po_nhi_nexthop), ( buf), (*buf)); | |||
2828 | break; | |||
2829 | ||||
2830 | case IPV6_2292HOPOPTS22: | |||
2831 | case IPV6_HOPOPTS49: | |||
2832 | { | |||
2833 | struct ip6_hbh *hbh; | |||
2834 | int hbhlen; | |||
2835 | ||||
2836 | /* | |||
2837 | * XXX: We don't allow a non-privileged user to set ANY HbH | |||
2838 | * options, since per-option restriction has too much | |||
2839 | * overhead. | |||
2840 | */ | |||
2841 | if (cred != NULL((void *)0)) { | |||
2842 | error = priv_check_cred(cred, PRIV_NETINET_SETHDROPTS505); | |||
2843 | if (error) | |||
2844 | return (error); | |||
2845 | } | |||
2846 | ||||
2847 | if (len == 0) { | |||
2848 | ip6_clearpktopts(opt, IPV6_HOPOPTS49); | |||
2849 | break; /* just remove the option */ | |||
2850 | } | |||
2851 | ||||
2852 | /* message length validation */ | |||
2853 | if (len < sizeof(struct ip6_hbh)) | |||
2854 | return (EINVAL22); | |||
2855 | hbh = (struct ip6_hbh *)buf; | |||
2856 | hbhlen = (hbh->ip6h_len + 1) << 3; | |||
2857 | if (len != hbhlen) | |||
2858 | return (EINVAL22); | |||
2859 | ||||
2860 | /* turn off the previous option, then set the new option. */ | |||
2861 | ip6_clearpktopts(opt, IPV6_HOPOPTS49); | |||
2862 | opt->ip6po_hbh = malloc(hbhlen, M_IP6OPT, M_NOWAIT0x0001); | |||
2863 | if (opt->ip6po_hbh == NULL((void *)0)) | |||
2864 | return (ENOBUFS55); | |||
2865 | bcopy(hbh, opt->ip6po_hbh, hbhlen)__builtin_memmove((opt->ip6po_hbh), (hbh), (hbhlen)); | |||
2866 | ||||
2867 | break; | |||
2868 | } | |||
2869 | ||||
2870 | case IPV6_2292DSTOPTS23: | |||
2871 | case IPV6_DSTOPTS50: | |||
2872 | case IPV6_RTHDRDSTOPTS35: | |||
2873 | { | |||
2874 | struct ip6_dest *dest, **newdest = NULL((void *)0); | |||
2875 | int destlen; | |||
2876 | ||||
2877 | if (cred != NULL((void *)0)) { /* XXX: see the comment for IPV6_HOPOPTS */ | |||
2878 | error = priv_check_cred(cred, PRIV_NETINET_SETHDROPTS505); | |||
2879 | if (error) | |||
2880 | return (error); | |||
2881 | } | |||
2882 | ||||
2883 | if (len == 0) { | |||
2884 | ip6_clearpktopts(opt, optname); | |||
2885 | break; /* just remove the option */ | |||
2886 | } | |||
2887 | ||||
2888 | /* message length validation */ | |||
2889 | if (len < sizeof(struct ip6_dest)) | |||
2890 | return (EINVAL22); | |||
2891 | dest = (struct ip6_dest *)buf; | |||
2892 | destlen = (dest->ip6d_len + 1) << 3; | |||
2893 | if (len != destlen) | |||
2894 | return (EINVAL22); | |||
2895 | ||||
2896 | /* | |||
2897 | * Determine the position that the destination options header | |||
2898 | * should be inserted; before or after the routing header. | |||
2899 | */ | |||
2900 | switch (optname) { | |||
2901 | case IPV6_2292DSTOPTS23: | |||
2902 | /* | |||
2903 | * The old advacned API is ambiguous on this point. | |||
2904 | * Our approach is to determine the position based | |||
2905 | * according to the existence of a routing header. | |||
2906 | * Note, however, that this depends on the order of the | |||
2907 | * extension headers in the ancillary data; the 1st | |||
2908 | * part of the destination options header must appear | |||
2909 | * before the routing header in the ancillary data, | |||
2910 | * too. | |||
2911 | * RFC3542 solved the ambiguity by introducing | |||
2912 | * separate ancillary data or option types. | |||
2913 | */ | |||
2914 | if (opt->ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr == NULL((void *)0)) | |||
2915 | newdest = &opt->ip6po_dest1; | |||
2916 | else | |||
2917 | newdest = &opt->ip6po_dest2; | |||
2918 | break; | |||
2919 | case IPV6_RTHDRDSTOPTS35: | |||
2920 | newdest = &opt->ip6po_dest1; | |||
2921 | break; | |||
2922 | case IPV6_DSTOPTS50: | |||
2923 | newdest = &opt->ip6po_dest2; | |||
2924 | break; | |||
2925 | } | |||
2926 | ||||
2927 | /* turn off the previous option, then set the new option. */ | |||
2928 | ip6_clearpktopts(opt, optname); | |||
2929 | *newdest = malloc(destlen, M_IP6OPT, M_NOWAIT0x0001); | |||
2930 | if (*newdest == NULL((void *)0)) | |||
2931 | return (ENOBUFS55); | |||
2932 | bcopy(dest, *newdest, destlen)__builtin_memmove((*newdest), (dest), (destlen)); | |||
2933 | ||||
2934 | break; | |||
2935 | } | |||
2936 | ||||
2937 | case IPV6_2292RTHDR24: | |||
2938 | case IPV6_RTHDR51: | |||
2939 | { | |||
2940 | struct ip6_rthdr *rth; | |||
2941 | int rthlen; | |||
2942 | ||||
2943 | if (len == 0) { | |||
2944 | ip6_clearpktopts(opt, IPV6_RTHDR51); | |||
2945 | break; /* just remove the option */ | |||
2946 | } | |||
2947 | ||||
2948 | /* message length validation */ | |||
2949 | if (len < sizeof(struct ip6_rthdr)) | |||
2950 | return (EINVAL22); | |||
2951 | rth = (struct ip6_rthdr *)buf; | |||
2952 | rthlen = (rth->ip6r_len + 1) << 3; | |||
2953 | if (len != rthlen) | |||
2954 | return (EINVAL22); | |||
2955 | ||||
2956 | switch (rth->ip6r_type) { | |||
2957 | case IPV6_RTHDR_TYPE_00: | |||
2958 | if (rth->ip6r_len == 0) /* must contain one addr */ | |||
2959 | return (EINVAL22); | |||
2960 | if (rth->ip6r_len % 2) /* length must be even */ | |||
2961 | return (EINVAL22); | |||
2962 | if (rth->ip6r_len / 2 != rth->ip6r_segleft) | |||
2963 | return (EINVAL22); | |||
2964 | break; | |||
2965 | default: | |||
2966 | return (EINVAL22); /* not supported */ | |||
2967 | } | |||
2968 | ||||
2969 | /* turn off the previous option */ | |||
2970 | ip6_clearpktopts(opt, IPV6_RTHDR51); | |||
2971 | opt->ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr = malloc(rthlen, M_IP6OPT, M_NOWAIT0x0001); | |||
2972 | if (opt->ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr == NULL((void *)0)) | |||
2973 | return (ENOBUFS55); | |||
2974 | bcopy(rth, opt->ip6po_rthdr, rthlen)__builtin_memmove((opt->ip6po_rhinfo.ip6po_rhi_rthdr), (rth ), (rthlen)); | |||
2975 | ||||
2976 | break; | |||
2977 | } | |||
2978 | ||||
2979 | case IPV6_USE_MIN_MTU42: | |||
2980 | if (len != sizeof(int)) | |||
2981 | return (EINVAL22); | |||
2982 | minmtupolicy = *(int *)buf; | |||
2983 | if (minmtupolicy != IP6PO_MINMTU_MCASTONLY-1 && | |||
2984 | minmtupolicy != IP6PO_MINMTU_DISABLE0 && | |||
2985 | minmtupolicy != IP6PO_MINMTU_ALL1) { | |||
2986 | return (EINVAL22); | |||
2987 | } | |||
2988 | opt->ip6po_minmtu = minmtupolicy; | |||
2989 | break; | |||
2990 | ||||
2991 | case IPV6_DONTFRAG62: | |||
2992 | if (len != sizeof(int)) | |||
2993 | return (EINVAL22); | |||
2994 | ||||
2995 | if (uproto == IPPROTO_TCP6 || *(int *)buf == 0) { | |||
2996 | /* | |||
2997 | * we ignore this option for TCP sockets. | |||
2998 | * (RFC3542 leaves this case unspecified.) | |||
2999 | */ | |||
3000 | opt->ip6po_flags &= ~IP6PO_DONTFRAG0x04; | |||
3001 | } else | |||
3002 | opt->ip6po_flags |= IP6PO_DONTFRAG0x04; | |||
3003 | break; | |||
3004 | ||||
3005 | case IPV6_PREFER_TEMPADDR63: | |||
3006 | if (len != sizeof(int)) | |||
3007 | return (EINVAL22); | |||
3008 | preftemp = *(int *)buf; | |||
3009 | if (preftemp != IP6PO_TEMPADDR_SYSTEM-1 && | |||
3010 | preftemp != IP6PO_TEMPADDR_NOTPREFER0 && | |||
3011 | preftemp != IP6PO_TEMPADDR_PREFER1) { | |||
3012 | return (EINVAL22); | |||
3013 | } | |||
3014 | opt->ip6po_prefer_tempaddr = preftemp; | |||
3015 | break; | |||
3016 | ||||
3017 | default: | |||
3018 | return (ENOPROTOOPT42); | |||
3019 | } /* end of switch */ | |||
3020 | ||||
3021 | return (0); | |||
3022 | } | |||
3023 | ||||
3024 | /* | |||
3025 | * Routine called from ip6_output() to loop back a copy of an IP6 multicast | |||
3026 | * packet to the input queue of a specified interface. Note that this | |||
3027 | * calls the output routine of the loopback "driver", but with an interface | |||
3028 | * pointer that might NOT be &loif -- easier than replicating that code here. | |||
3029 | */ | |||
3030 | void | |||
3031 | ip6_mloopback(struct ifnet *ifp, struct mbuf *m) | |||
3032 | { | |||
3033 | struct mbuf *copym; | |||
3034 | struct ip6_hdr *ip6; | |||
3035 | ||||
3036 | copym = m_copym(m, 0, M_COPYALL1000000000, M_NOWAIT0x0001); | |||
3037 | if (copym == NULL((void *)0)) | |||
3038 | return; | |||
3039 | ||||
3040 | /* | |||
3041 | * Make sure to deep-copy IPv6 header portion in case the data | |||
3042 | * is in an mbuf cluster, so that we can safely override the IPv6 | |||
3043 | * header portion later. | |||
3044 | */ | |||
3045 | if (!M_WRITABLE(copym)(!((copym)->m_flags & 0x00000008) && (!(((copym )->m_flags & 0x00000001)) || (m_extrefcnt(copym) == 1) )) || | |||
3046 | copym->m_len < sizeof(struct ip6_hdr)) { | |||
3047 | copym = m_pullup(copym, sizeof(struct ip6_hdr)); | |||
3048 | if (copym == NULL((void *)0)) | |||
3049 | return; | |||
3050 | } | |||
3051 | ip6 = mtod(copym, struct ip6_hdr *)((struct ip6_hdr *)((copym)->m_data)); | |||
3052 | /* | |||
3053 | * clear embedded scope identifiers if necessary. | |||
3054 | * in6_clearscope will touch the addresses only when necessary. | |||
3055 | */ | |||
3056 | in6_clearscope(&ip6->ip6_src); | |||
3057 | in6_clearscope(&ip6->ip6_dst); | |||
3058 | if (copym->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6(0x00000400|0x00000200)) { | |||
3059 | copym->m_pkthdr.csum_flags |= CSUM_DATA_VALID_IPV60x08000000 | | |||
3060 | CSUM_PSEUDO_HDR0x04000000; | |||
3061 | copym->m_pkthdr.csum_dataPH_per.thirtytwo[1] = 0xffff; | |||
3062 | } | |||
3063 | if_simloop(ifp, copym, AF_INET628, 0); | |||
3064 | } | |||
3065 | ||||
3066 | /* | |||
3067 | * Chop IPv6 header off from the payload. | |||
3068 | */ | |||
3069 | static int | |||
3070 | ip6_splithdr(struct mbuf *m, struct ip6_exthdrs *exthdrs) | |||
3071 | { | |||
3072 | struct mbuf *mh; | |||
3073 | struct ip6_hdr *ip6; | |||
3074 | ||||
3075 | ip6 = mtod(m, struct ip6_hdr *)((struct ip6_hdr *)((m)->m_data)); | |||
3076 | if (m->m_len > sizeof(*ip6)) { | |||
3077 | mh = m_gethdr(M_NOWAIT0x0001, MT_DATA1); | |||
3078 | if (mh == NULL((void *)0)) { | |||
3079 | m_freem(m); | |||
3080 | return ENOBUFS55; | |||
3081 | } | |||
3082 | m_move_pkthdr(mh, m); | |||
3083 | M_ALIGN(mh, sizeof(*ip6))m_align(mh, sizeof(*ip6)); | |||
3084 | m->m_len -= sizeof(*ip6); | |||
3085 | m->m_data += sizeof(*ip6); | |||
3086 | mh->m_next = m; | |||
3087 | m = mh; | |||
3088 | m->m_len = sizeof(*ip6); | |||
3089 | bcopy((caddr_t)ip6, mtod(m, caddr_t), sizeof(*ip6))__builtin_memmove((((caddr_t)((m)->m_data))), ((caddr_t)ip6 ), (sizeof(*ip6))); | |||
3090 | } | |||
3091 | exthdrs->ip6e_ip6 = m; | |||
3092 | return 0; | |||
3093 | } | |||
3094 | ||||
3095 | /* | |||
3096 | * Compute IPv6 extension header length. | |||
3097 | */ | |||
3098 | int | |||
3099 | ip6_optlen(struct inpcb *in6p) | |||
3100 | { | |||
3101 | int len; | |||
3102 | ||||
3103 | if (!in6p->in6p_outputopts) | |||
3104 | return 0; | |||
3105 | ||||
3106 | len = 0; | |||
3107 | #define elen(x) \ | |||
3108 | (((struct ip6_ext *)(x)) ? (((struct ip6_ext *)(x))->ip6e_len + 1) << 3 : 0) | |||
3109 | ||||
3110 | len += elen(in6p->in6p_outputopts->ip6po_hbh); | |||
3111 | if (in6p->in6p_outputopts->ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr) | |||
3112 | /* dest1 is valid with rthdr only */ | |||
3113 | len += elen(in6p->in6p_outputopts->ip6po_dest1); | |||
3114 | len += elen(in6p->in6p_outputopts->ip6po_rthdrip6po_rhinfo.ip6po_rhi_rthdr); | |||
3115 | len += elen(in6p->in6p_outputopts->ip6po_dest2); | |||
3116 | return len; | |||
3117 | #undef elen | |||
3118 | } |