Commit 68536053600425c24aba031c45f053d447eedd9c
Committed by
David S. Miller
1 parent
335802d1c2
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
ipv6: fix incorrect type in declaration
Introduced by 1397ed35f22d7c30d0b89ba74b6b7829220dfcfd "ipv6: add flowinfo for tcp6 pkt_options for all cases" Reported-by: kbuild test robot <fengguang.wu@intel.com> V2: fix the title, add empty line after the declaration (Sergei Shtylyov feedbacks) Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 2 additions and 1 deletions Inline Diff
net/ipv6/ipv6_sockglue.c
1 | /* | 1 | /* |
2 | * IPv6 BSD socket options interface | 2 | * IPv6 BSD socket options interface |
3 | * Linux INET6 implementation | 3 | * Linux INET6 implementation |
4 | * | 4 | * |
5 | * Authors: | 5 | * Authors: |
6 | * Pedro Roque <roque@di.fc.ul.pt> | 6 | * Pedro Roque <roque@di.fc.ul.pt> |
7 | * | 7 | * |
8 | * Based on linux/net/ipv4/ip_sockglue.c | 8 | * Based on linux/net/ipv4/ip_sockglue.c |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or | 10 | * This program is free software; you can redistribute it and/or |
11 | * modify it under the terms of the GNU General Public License | 11 | * modify it under the terms of the GNU General Public License |
12 | * as published by the Free Software Foundation; either version | 12 | * as published by the Free Software Foundation; either version |
13 | * 2 of the License, or (at your option) any later version. | 13 | * 2 of the License, or (at your option) any later version. |
14 | * | 14 | * |
15 | * FIXME: Make the setsockopt code POSIX compliant: That is | 15 | * FIXME: Make the setsockopt code POSIX compliant: That is |
16 | * | 16 | * |
17 | * o Truncate getsockopt returns | 17 | * o Truncate getsockopt returns |
18 | * o Return an optlen of the truncated length if need be | 18 | * o Return an optlen of the truncated length if need be |
19 | * | 19 | * |
20 | * Changes: | 20 | * Changes: |
21 | * David L Stevens <dlstevens@us.ibm.com>: | 21 | * David L Stevens <dlstevens@us.ibm.com>: |
22 | * - added multicast source filtering API for MLDv2 | 22 | * - added multicast source filtering API for MLDv2 |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/capability.h> | 26 | #include <linux/capability.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/types.h> | 28 | #include <linux/types.h> |
29 | #include <linux/socket.h> | 29 | #include <linux/socket.h> |
30 | #include <linux/sockios.h> | 30 | #include <linux/sockios.h> |
31 | #include <linux/net.h> | 31 | #include <linux/net.h> |
32 | #include <linux/in6.h> | 32 | #include <linux/in6.h> |
33 | #include <linux/mroute6.h> | 33 | #include <linux/mroute6.h> |
34 | #include <linux/netdevice.h> | 34 | #include <linux/netdevice.h> |
35 | #include <linux/if_arp.h> | 35 | #include <linux/if_arp.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/sysctl.h> | 37 | #include <linux/sysctl.h> |
38 | #include <linux/netfilter.h> | 38 | #include <linux/netfilter.h> |
39 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
40 | 40 | ||
41 | #include <net/sock.h> | 41 | #include <net/sock.h> |
42 | #include <net/snmp.h> | 42 | #include <net/snmp.h> |
43 | #include <net/ipv6.h> | 43 | #include <net/ipv6.h> |
44 | #include <net/ndisc.h> | 44 | #include <net/ndisc.h> |
45 | #include <net/protocol.h> | 45 | #include <net/protocol.h> |
46 | #include <net/transp_v6.h> | 46 | #include <net/transp_v6.h> |
47 | #include <net/ip6_route.h> | 47 | #include <net/ip6_route.h> |
48 | #include <net/addrconf.h> | 48 | #include <net/addrconf.h> |
49 | #include <net/inet_common.h> | 49 | #include <net/inet_common.h> |
50 | #include <net/tcp.h> | 50 | #include <net/tcp.h> |
51 | #include <net/udp.h> | 51 | #include <net/udp.h> |
52 | #include <net/udplite.h> | 52 | #include <net/udplite.h> |
53 | #include <net/xfrm.h> | 53 | #include <net/xfrm.h> |
54 | #include <net/compat.h> | 54 | #include <net/compat.h> |
55 | 55 | ||
56 | #include <asm/uaccess.h> | 56 | #include <asm/uaccess.h> |
57 | 57 | ||
58 | struct ip6_ra_chain *ip6_ra_chain; | 58 | struct ip6_ra_chain *ip6_ra_chain; |
59 | DEFINE_RWLOCK(ip6_ra_lock); | 59 | DEFINE_RWLOCK(ip6_ra_lock); |
60 | 60 | ||
61 | int ip6_ra_control(struct sock *sk, int sel) | 61 | int ip6_ra_control(struct sock *sk, int sel) |
62 | { | 62 | { |
63 | struct ip6_ra_chain *ra, *new_ra, **rap; | 63 | struct ip6_ra_chain *ra, *new_ra, **rap; |
64 | 64 | ||
65 | /* RA packet may be delivered ONLY to IPPROTO_RAW socket */ | 65 | /* RA packet may be delivered ONLY to IPPROTO_RAW socket */ |
66 | if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num != IPPROTO_RAW) | 66 | if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num != IPPROTO_RAW) |
67 | return -ENOPROTOOPT; | 67 | return -ENOPROTOOPT; |
68 | 68 | ||
69 | new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; | 69 | new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; |
70 | 70 | ||
71 | write_lock_bh(&ip6_ra_lock); | 71 | write_lock_bh(&ip6_ra_lock); |
72 | for (rap = &ip6_ra_chain; (ra=*rap) != NULL; rap = &ra->next) { | 72 | for (rap = &ip6_ra_chain; (ra=*rap) != NULL; rap = &ra->next) { |
73 | if (ra->sk == sk) { | 73 | if (ra->sk == sk) { |
74 | if (sel>=0) { | 74 | if (sel>=0) { |
75 | write_unlock_bh(&ip6_ra_lock); | 75 | write_unlock_bh(&ip6_ra_lock); |
76 | kfree(new_ra); | 76 | kfree(new_ra); |
77 | return -EADDRINUSE; | 77 | return -EADDRINUSE; |
78 | } | 78 | } |
79 | 79 | ||
80 | *rap = ra->next; | 80 | *rap = ra->next; |
81 | write_unlock_bh(&ip6_ra_lock); | 81 | write_unlock_bh(&ip6_ra_lock); |
82 | 82 | ||
83 | sock_put(sk); | 83 | sock_put(sk); |
84 | kfree(ra); | 84 | kfree(ra); |
85 | return 0; | 85 | return 0; |
86 | } | 86 | } |
87 | } | 87 | } |
88 | if (new_ra == NULL) { | 88 | if (new_ra == NULL) { |
89 | write_unlock_bh(&ip6_ra_lock); | 89 | write_unlock_bh(&ip6_ra_lock); |
90 | return -ENOBUFS; | 90 | return -ENOBUFS; |
91 | } | 91 | } |
92 | new_ra->sk = sk; | 92 | new_ra->sk = sk; |
93 | new_ra->sel = sel; | 93 | new_ra->sel = sel; |
94 | new_ra->next = ra; | 94 | new_ra->next = ra; |
95 | *rap = new_ra; | 95 | *rap = new_ra; |
96 | sock_hold(sk); | 96 | sock_hold(sk); |
97 | write_unlock_bh(&ip6_ra_lock); | 97 | write_unlock_bh(&ip6_ra_lock); |
98 | return 0; | 98 | return 0; |
99 | } | 99 | } |
100 | 100 | ||
101 | static | 101 | static |
102 | struct ipv6_txoptions *ipv6_update_options(struct sock *sk, | 102 | struct ipv6_txoptions *ipv6_update_options(struct sock *sk, |
103 | struct ipv6_txoptions *opt) | 103 | struct ipv6_txoptions *opt) |
104 | { | 104 | { |
105 | if (inet_sk(sk)->is_icsk) { | 105 | if (inet_sk(sk)->is_icsk) { |
106 | if (opt && | 106 | if (opt && |
107 | !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) && | 107 | !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) && |
108 | inet_sk(sk)->inet_daddr != LOOPBACK4_IPV6) { | 108 | inet_sk(sk)->inet_daddr != LOOPBACK4_IPV6) { |
109 | struct inet_connection_sock *icsk = inet_csk(sk); | 109 | struct inet_connection_sock *icsk = inet_csk(sk); |
110 | icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen; | 110 | icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen; |
111 | icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); | 111 | icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); |
112 | } | 112 | } |
113 | opt = xchg(&inet6_sk(sk)->opt, opt); | 113 | opt = xchg(&inet6_sk(sk)->opt, opt); |
114 | } else { | 114 | } else { |
115 | spin_lock(&sk->sk_dst_lock); | 115 | spin_lock(&sk->sk_dst_lock); |
116 | opt = xchg(&inet6_sk(sk)->opt, opt); | 116 | opt = xchg(&inet6_sk(sk)->opt, opt); |
117 | spin_unlock(&sk->sk_dst_lock); | 117 | spin_unlock(&sk->sk_dst_lock); |
118 | } | 118 | } |
119 | sk_dst_reset(sk); | 119 | sk_dst_reset(sk); |
120 | 120 | ||
121 | return opt; | 121 | return opt; |
122 | } | 122 | } |
123 | 123 | ||
124 | static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, | 124 | static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, |
125 | char __user *optval, unsigned int optlen) | 125 | char __user *optval, unsigned int optlen) |
126 | { | 126 | { |
127 | struct ipv6_pinfo *np = inet6_sk(sk); | 127 | struct ipv6_pinfo *np = inet6_sk(sk); |
128 | struct net *net = sock_net(sk); | 128 | struct net *net = sock_net(sk); |
129 | int val, valbool; | 129 | int val, valbool; |
130 | int retv = -ENOPROTOOPT; | 130 | int retv = -ENOPROTOOPT; |
131 | 131 | ||
132 | if (optval == NULL) | 132 | if (optval == NULL) |
133 | val=0; | 133 | val=0; |
134 | else { | 134 | else { |
135 | if (optlen >= sizeof(int)) { | 135 | if (optlen >= sizeof(int)) { |
136 | if (get_user(val, (int __user *) optval)) | 136 | if (get_user(val, (int __user *) optval)) |
137 | return -EFAULT; | 137 | return -EFAULT; |
138 | } else | 138 | } else |
139 | val = 0; | 139 | val = 0; |
140 | } | 140 | } |
141 | 141 | ||
142 | valbool = (val!=0); | 142 | valbool = (val!=0); |
143 | 143 | ||
144 | if (ip6_mroute_opt(optname)) | 144 | if (ip6_mroute_opt(optname)) |
145 | return ip6_mroute_setsockopt(sk, optname, optval, optlen); | 145 | return ip6_mroute_setsockopt(sk, optname, optval, optlen); |
146 | 146 | ||
147 | lock_sock(sk); | 147 | lock_sock(sk); |
148 | 148 | ||
149 | switch (optname) { | 149 | switch (optname) { |
150 | 150 | ||
151 | case IPV6_ADDRFORM: | 151 | case IPV6_ADDRFORM: |
152 | if (optlen < sizeof(int)) | 152 | if (optlen < sizeof(int)) |
153 | goto e_inval; | 153 | goto e_inval; |
154 | if (val == PF_INET) { | 154 | if (val == PF_INET) { |
155 | struct ipv6_txoptions *opt; | 155 | struct ipv6_txoptions *opt; |
156 | struct sk_buff *pktopt; | 156 | struct sk_buff *pktopt; |
157 | 157 | ||
158 | if (sk->sk_type == SOCK_RAW) | 158 | if (sk->sk_type == SOCK_RAW) |
159 | break; | 159 | break; |
160 | 160 | ||
161 | if (sk->sk_protocol == IPPROTO_UDP || | 161 | if (sk->sk_protocol == IPPROTO_UDP || |
162 | sk->sk_protocol == IPPROTO_UDPLITE) { | 162 | sk->sk_protocol == IPPROTO_UDPLITE) { |
163 | struct udp_sock *up = udp_sk(sk); | 163 | struct udp_sock *up = udp_sk(sk); |
164 | if (up->pending == AF_INET6) { | 164 | if (up->pending == AF_INET6) { |
165 | retv = -EBUSY; | 165 | retv = -EBUSY; |
166 | break; | 166 | break; |
167 | } | 167 | } |
168 | } else if (sk->sk_protocol != IPPROTO_TCP) | 168 | } else if (sk->sk_protocol != IPPROTO_TCP) |
169 | break; | 169 | break; |
170 | 170 | ||
171 | if (sk->sk_state != TCP_ESTABLISHED) { | 171 | if (sk->sk_state != TCP_ESTABLISHED) { |
172 | retv = -ENOTCONN; | 172 | retv = -ENOTCONN; |
173 | break; | 173 | break; |
174 | } | 174 | } |
175 | 175 | ||
176 | if (ipv6_only_sock(sk) || | 176 | if (ipv6_only_sock(sk) || |
177 | !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) { | 177 | !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) { |
178 | retv = -EADDRNOTAVAIL; | 178 | retv = -EADDRNOTAVAIL; |
179 | break; | 179 | break; |
180 | } | 180 | } |
181 | 181 | ||
182 | fl6_free_socklist(sk); | 182 | fl6_free_socklist(sk); |
183 | ipv6_sock_mc_close(sk); | 183 | ipv6_sock_mc_close(sk); |
184 | 184 | ||
185 | /* | 185 | /* |
186 | * Sock is moving from IPv6 to IPv4 (sk_prot), so | 186 | * Sock is moving from IPv6 to IPv4 (sk_prot), so |
187 | * remove it from the refcnt debug socks count in the | 187 | * remove it from the refcnt debug socks count in the |
188 | * original family... | 188 | * original family... |
189 | */ | 189 | */ |
190 | sk_refcnt_debug_dec(sk); | 190 | sk_refcnt_debug_dec(sk); |
191 | 191 | ||
192 | if (sk->sk_protocol == IPPROTO_TCP) { | 192 | if (sk->sk_protocol == IPPROTO_TCP) { |
193 | struct inet_connection_sock *icsk = inet_csk(sk); | 193 | struct inet_connection_sock *icsk = inet_csk(sk); |
194 | local_bh_disable(); | 194 | local_bh_disable(); |
195 | sock_prot_inuse_add(net, sk->sk_prot, -1); | 195 | sock_prot_inuse_add(net, sk->sk_prot, -1); |
196 | sock_prot_inuse_add(net, &tcp_prot, 1); | 196 | sock_prot_inuse_add(net, &tcp_prot, 1); |
197 | local_bh_enable(); | 197 | local_bh_enable(); |
198 | sk->sk_prot = &tcp_prot; | 198 | sk->sk_prot = &tcp_prot; |
199 | icsk->icsk_af_ops = &ipv4_specific; | 199 | icsk->icsk_af_ops = &ipv4_specific; |
200 | sk->sk_socket->ops = &inet_stream_ops; | 200 | sk->sk_socket->ops = &inet_stream_ops; |
201 | sk->sk_family = PF_INET; | 201 | sk->sk_family = PF_INET; |
202 | tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); | 202 | tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); |
203 | } else { | 203 | } else { |
204 | struct proto *prot = &udp_prot; | 204 | struct proto *prot = &udp_prot; |
205 | 205 | ||
206 | if (sk->sk_protocol == IPPROTO_UDPLITE) | 206 | if (sk->sk_protocol == IPPROTO_UDPLITE) |
207 | prot = &udplite_prot; | 207 | prot = &udplite_prot; |
208 | local_bh_disable(); | 208 | local_bh_disable(); |
209 | sock_prot_inuse_add(net, sk->sk_prot, -1); | 209 | sock_prot_inuse_add(net, sk->sk_prot, -1); |
210 | sock_prot_inuse_add(net, prot, 1); | 210 | sock_prot_inuse_add(net, prot, 1); |
211 | local_bh_enable(); | 211 | local_bh_enable(); |
212 | sk->sk_prot = prot; | 212 | sk->sk_prot = prot; |
213 | sk->sk_socket->ops = &inet_dgram_ops; | 213 | sk->sk_socket->ops = &inet_dgram_ops; |
214 | sk->sk_family = PF_INET; | 214 | sk->sk_family = PF_INET; |
215 | } | 215 | } |
216 | opt = xchg(&np->opt, NULL); | 216 | opt = xchg(&np->opt, NULL); |
217 | if (opt) | 217 | if (opt) |
218 | sock_kfree_s(sk, opt, opt->tot_len); | 218 | sock_kfree_s(sk, opt, opt->tot_len); |
219 | pktopt = xchg(&np->pktoptions, NULL); | 219 | pktopt = xchg(&np->pktoptions, NULL); |
220 | kfree_skb(pktopt); | 220 | kfree_skb(pktopt); |
221 | 221 | ||
222 | sk->sk_destruct = inet_sock_destruct; | 222 | sk->sk_destruct = inet_sock_destruct; |
223 | /* | 223 | /* |
224 | * ... and add it to the refcnt debug socks count | 224 | * ... and add it to the refcnt debug socks count |
225 | * in the new family. -acme | 225 | * in the new family. -acme |
226 | */ | 226 | */ |
227 | sk_refcnt_debug_inc(sk); | 227 | sk_refcnt_debug_inc(sk); |
228 | module_put(THIS_MODULE); | 228 | module_put(THIS_MODULE); |
229 | retv = 0; | 229 | retv = 0; |
230 | break; | 230 | break; |
231 | } | 231 | } |
232 | goto e_inval; | 232 | goto e_inval; |
233 | 233 | ||
234 | case IPV6_V6ONLY: | 234 | case IPV6_V6ONLY: |
235 | if (optlen < sizeof(int) || | 235 | if (optlen < sizeof(int) || |
236 | inet_sk(sk)->inet_num) | 236 | inet_sk(sk)->inet_num) |
237 | goto e_inval; | 237 | goto e_inval; |
238 | np->ipv6only = valbool; | 238 | np->ipv6only = valbool; |
239 | retv = 0; | 239 | retv = 0; |
240 | break; | 240 | break; |
241 | 241 | ||
242 | case IPV6_RECVPKTINFO: | 242 | case IPV6_RECVPKTINFO: |
243 | if (optlen < sizeof(int)) | 243 | if (optlen < sizeof(int)) |
244 | goto e_inval; | 244 | goto e_inval; |
245 | np->rxopt.bits.rxinfo = valbool; | 245 | np->rxopt.bits.rxinfo = valbool; |
246 | retv = 0; | 246 | retv = 0; |
247 | break; | 247 | break; |
248 | 248 | ||
249 | case IPV6_2292PKTINFO: | 249 | case IPV6_2292PKTINFO: |
250 | if (optlen < sizeof(int)) | 250 | if (optlen < sizeof(int)) |
251 | goto e_inval; | 251 | goto e_inval; |
252 | np->rxopt.bits.rxoinfo = valbool; | 252 | np->rxopt.bits.rxoinfo = valbool; |
253 | retv = 0; | 253 | retv = 0; |
254 | break; | 254 | break; |
255 | 255 | ||
256 | case IPV6_RECVHOPLIMIT: | 256 | case IPV6_RECVHOPLIMIT: |
257 | if (optlen < sizeof(int)) | 257 | if (optlen < sizeof(int)) |
258 | goto e_inval; | 258 | goto e_inval; |
259 | np->rxopt.bits.rxhlim = valbool; | 259 | np->rxopt.bits.rxhlim = valbool; |
260 | retv = 0; | 260 | retv = 0; |
261 | break; | 261 | break; |
262 | 262 | ||
263 | case IPV6_2292HOPLIMIT: | 263 | case IPV6_2292HOPLIMIT: |
264 | if (optlen < sizeof(int)) | 264 | if (optlen < sizeof(int)) |
265 | goto e_inval; | 265 | goto e_inval; |
266 | np->rxopt.bits.rxohlim = valbool; | 266 | np->rxopt.bits.rxohlim = valbool; |
267 | retv = 0; | 267 | retv = 0; |
268 | break; | 268 | break; |
269 | 269 | ||
270 | case IPV6_RECVRTHDR: | 270 | case IPV6_RECVRTHDR: |
271 | if (optlen < sizeof(int)) | 271 | if (optlen < sizeof(int)) |
272 | goto e_inval; | 272 | goto e_inval; |
273 | np->rxopt.bits.srcrt = valbool; | 273 | np->rxopt.bits.srcrt = valbool; |
274 | retv = 0; | 274 | retv = 0; |
275 | break; | 275 | break; |
276 | 276 | ||
277 | case IPV6_2292RTHDR: | 277 | case IPV6_2292RTHDR: |
278 | if (optlen < sizeof(int)) | 278 | if (optlen < sizeof(int)) |
279 | goto e_inval; | 279 | goto e_inval; |
280 | np->rxopt.bits.osrcrt = valbool; | 280 | np->rxopt.bits.osrcrt = valbool; |
281 | retv = 0; | 281 | retv = 0; |
282 | break; | 282 | break; |
283 | 283 | ||
284 | case IPV6_RECVHOPOPTS: | 284 | case IPV6_RECVHOPOPTS: |
285 | if (optlen < sizeof(int)) | 285 | if (optlen < sizeof(int)) |
286 | goto e_inval; | 286 | goto e_inval; |
287 | np->rxopt.bits.hopopts = valbool; | 287 | np->rxopt.bits.hopopts = valbool; |
288 | retv = 0; | 288 | retv = 0; |
289 | break; | 289 | break; |
290 | 290 | ||
291 | case IPV6_2292HOPOPTS: | 291 | case IPV6_2292HOPOPTS: |
292 | if (optlen < sizeof(int)) | 292 | if (optlen < sizeof(int)) |
293 | goto e_inval; | 293 | goto e_inval; |
294 | np->rxopt.bits.ohopopts = valbool; | 294 | np->rxopt.bits.ohopopts = valbool; |
295 | retv = 0; | 295 | retv = 0; |
296 | break; | 296 | break; |
297 | 297 | ||
298 | case IPV6_RECVDSTOPTS: | 298 | case IPV6_RECVDSTOPTS: |
299 | if (optlen < sizeof(int)) | 299 | if (optlen < sizeof(int)) |
300 | goto e_inval; | 300 | goto e_inval; |
301 | np->rxopt.bits.dstopts = valbool; | 301 | np->rxopt.bits.dstopts = valbool; |
302 | retv = 0; | 302 | retv = 0; |
303 | break; | 303 | break; |
304 | 304 | ||
305 | case IPV6_2292DSTOPTS: | 305 | case IPV6_2292DSTOPTS: |
306 | if (optlen < sizeof(int)) | 306 | if (optlen < sizeof(int)) |
307 | goto e_inval; | 307 | goto e_inval; |
308 | np->rxopt.bits.odstopts = valbool; | 308 | np->rxopt.bits.odstopts = valbool; |
309 | retv = 0; | 309 | retv = 0; |
310 | break; | 310 | break; |
311 | 311 | ||
312 | case IPV6_TCLASS: | 312 | case IPV6_TCLASS: |
313 | if (optlen < sizeof(int)) | 313 | if (optlen < sizeof(int)) |
314 | goto e_inval; | 314 | goto e_inval; |
315 | if (val < -1 || val > 0xff) | 315 | if (val < -1 || val > 0xff) |
316 | goto e_inval; | 316 | goto e_inval; |
317 | /* RFC 3542, 6.5: default traffic class of 0x0 */ | 317 | /* RFC 3542, 6.5: default traffic class of 0x0 */ |
318 | if (val == -1) | 318 | if (val == -1) |
319 | val = 0; | 319 | val = 0; |
320 | np->tclass = val; | 320 | np->tclass = val; |
321 | retv = 0; | 321 | retv = 0; |
322 | break; | 322 | break; |
323 | 323 | ||
324 | case IPV6_RECVTCLASS: | 324 | case IPV6_RECVTCLASS: |
325 | if (optlen < sizeof(int)) | 325 | if (optlen < sizeof(int)) |
326 | goto e_inval; | 326 | goto e_inval; |
327 | np->rxopt.bits.rxtclass = valbool; | 327 | np->rxopt.bits.rxtclass = valbool; |
328 | retv = 0; | 328 | retv = 0; |
329 | break; | 329 | break; |
330 | 330 | ||
331 | case IPV6_FLOWINFO: | 331 | case IPV6_FLOWINFO: |
332 | if (optlen < sizeof(int)) | 332 | if (optlen < sizeof(int)) |
333 | goto e_inval; | 333 | goto e_inval; |
334 | np->rxopt.bits.rxflow = valbool; | 334 | np->rxopt.bits.rxflow = valbool; |
335 | retv = 0; | 335 | retv = 0; |
336 | break; | 336 | break; |
337 | 337 | ||
338 | case IPV6_RECVPATHMTU: | 338 | case IPV6_RECVPATHMTU: |
339 | if (optlen < sizeof(int)) | 339 | if (optlen < sizeof(int)) |
340 | goto e_inval; | 340 | goto e_inval; |
341 | np->rxopt.bits.rxpmtu = valbool; | 341 | np->rxopt.bits.rxpmtu = valbool; |
342 | retv = 0; | 342 | retv = 0; |
343 | break; | 343 | break; |
344 | 344 | ||
345 | case IPV6_TRANSPARENT: | 345 | case IPV6_TRANSPARENT: |
346 | if (valbool && !ns_capable(net->user_ns, CAP_NET_ADMIN) && | 346 | if (valbool && !ns_capable(net->user_ns, CAP_NET_ADMIN) && |
347 | !ns_capable(net->user_ns, CAP_NET_RAW)) { | 347 | !ns_capable(net->user_ns, CAP_NET_RAW)) { |
348 | retv = -EPERM; | 348 | retv = -EPERM; |
349 | break; | 349 | break; |
350 | } | 350 | } |
351 | if (optlen < sizeof(int)) | 351 | if (optlen < sizeof(int)) |
352 | goto e_inval; | 352 | goto e_inval; |
353 | /* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */ | 353 | /* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */ |
354 | inet_sk(sk)->transparent = valbool; | 354 | inet_sk(sk)->transparent = valbool; |
355 | retv = 0; | 355 | retv = 0; |
356 | break; | 356 | break; |
357 | 357 | ||
358 | case IPV6_RECVORIGDSTADDR: | 358 | case IPV6_RECVORIGDSTADDR: |
359 | if (optlen < sizeof(int)) | 359 | if (optlen < sizeof(int)) |
360 | goto e_inval; | 360 | goto e_inval; |
361 | np->rxopt.bits.rxorigdstaddr = valbool; | 361 | np->rxopt.bits.rxorigdstaddr = valbool; |
362 | retv = 0; | 362 | retv = 0; |
363 | break; | 363 | break; |
364 | 364 | ||
365 | case IPV6_HOPOPTS: | 365 | case IPV6_HOPOPTS: |
366 | case IPV6_RTHDRDSTOPTS: | 366 | case IPV6_RTHDRDSTOPTS: |
367 | case IPV6_RTHDR: | 367 | case IPV6_RTHDR: |
368 | case IPV6_DSTOPTS: | 368 | case IPV6_DSTOPTS: |
369 | { | 369 | { |
370 | struct ipv6_txoptions *opt; | 370 | struct ipv6_txoptions *opt; |
371 | 371 | ||
372 | /* remove any sticky options header with a zero option | 372 | /* remove any sticky options header with a zero option |
373 | * length, per RFC3542. | 373 | * length, per RFC3542. |
374 | */ | 374 | */ |
375 | if (optlen == 0) | 375 | if (optlen == 0) |
376 | optval = NULL; | 376 | optval = NULL; |
377 | else if (optval == NULL) | 377 | else if (optval == NULL) |
378 | goto e_inval; | 378 | goto e_inval; |
379 | else if (optlen < sizeof(struct ipv6_opt_hdr) || | 379 | else if (optlen < sizeof(struct ipv6_opt_hdr) || |
380 | optlen & 0x7 || optlen > 8 * 255) | 380 | optlen & 0x7 || optlen > 8 * 255) |
381 | goto e_inval; | 381 | goto e_inval; |
382 | 382 | ||
383 | /* hop-by-hop / destination options are privileged option */ | 383 | /* hop-by-hop / destination options are privileged option */ |
384 | retv = -EPERM; | 384 | retv = -EPERM; |
385 | if (optname != IPV6_RTHDR && !ns_capable(net->user_ns, CAP_NET_RAW)) | 385 | if (optname != IPV6_RTHDR && !ns_capable(net->user_ns, CAP_NET_RAW)) |
386 | break; | 386 | break; |
387 | 387 | ||
388 | opt = ipv6_renew_options(sk, np->opt, optname, | 388 | opt = ipv6_renew_options(sk, np->opt, optname, |
389 | (struct ipv6_opt_hdr __user *)optval, | 389 | (struct ipv6_opt_hdr __user *)optval, |
390 | optlen); | 390 | optlen); |
391 | if (IS_ERR(opt)) { | 391 | if (IS_ERR(opt)) { |
392 | retv = PTR_ERR(opt); | 392 | retv = PTR_ERR(opt); |
393 | break; | 393 | break; |
394 | } | 394 | } |
395 | 395 | ||
396 | /* routing header option needs extra check */ | 396 | /* routing header option needs extra check */ |
397 | retv = -EINVAL; | 397 | retv = -EINVAL; |
398 | if (optname == IPV6_RTHDR && opt && opt->srcrt) { | 398 | if (optname == IPV6_RTHDR && opt && opt->srcrt) { |
399 | struct ipv6_rt_hdr *rthdr = opt->srcrt; | 399 | struct ipv6_rt_hdr *rthdr = opt->srcrt; |
400 | switch (rthdr->type) { | 400 | switch (rthdr->type) { |
401 | #if IS_ENABLED(CONFIG_IPV6_MIP6) | 401 | #if IS_ENABLED(CONFIG_IPV6_MIP6) |
402 | case IPV6_SRCRT_TYPE_2: | 402 | case IPV6_SRCRT_TYPE_2: |
403 | if (rthdr->hdrlen != 2 || | 403 | if (rthdr->hdrlen != 2 || |
404 | rthdr->segments_left != 1) | 404 | rthdr->segments_left != 1) |
405 | goto sticky_done; | 405 | goto sticky_done; |
406 | 406 | ||
407 | break; | 407 | break; |
408 | #endif | 408 | #endif |
409 | default: | 409 | default: |
410 | goto sticky_done; | 410 | goto sticky_done; |
411 | } | 411 | } |
412 | } | 412 | } |
413 | 413 | ||
414 | retv = 0; | 414 | retv = 0; |
415 | opt = ipv6_update_options(sk, opt); | 415 | opt = ipv6_update_options(sk, opt); |
416 | sticky_done: | 416 | sticky_done: |
417 | if (opt) | 417 | if (opt) |
418 | sock_kfree_s(sk, opt, opt->tot_len); | 418 | sock_kfree_s(sk, opt, opt->tot_len); |
419 | break; | 419 | break; |
420 | } | 420 | } |
421 | 421 | ||
422 | case IPV6_PKTINFO: | 422 | case IPV6_PKTINFO: |
423 | { | 423 | { |
424 | struct in6_pktinfo pkt; | 424 | struct in6_pktinfo pkt; |
425 | 425 | ||
426 | if (optlen == 0) | 426 | if (optlen == 0) |
427 | goto e_inval; | 427 | goto e_inval; |
428 | else if (optlen < sizeof(struct in6_pktinfo) || optval == NULL) | 428 | else if (optlen < sizeof(struct in6_pktinfo) || optval == NULL) |
429 | goto e_inval; | 429 | goto e_inval; |
430 | 430 | ||
431 | if (copy_from_user(&pkt, optval, sizeof(struct in6_pktinfo))) { | 431 | if (copy_from_user(&pkt, optval, sizeof(struct in6_pktinfo))) { |
432 | retv = -EFAULT; | 432 | retv = -EFAULT; |
433 | break; | 433 | break; |
434 | } | 434 | } |
435 | if (sk->sk_bound_dev_if && pkt.ipi6_ifindex != sk->sk_bound_dev_if) | 435 | if (sk->sk_bound_dev_if && pkt.ipi6_ifindex != sk->sk_bound_dev_if) |
436 | goto e_inval; | 436 | goto e_inval; |
437 | 437 | ||
438 | np->sticky_pktinfo.ipi6_ifindex = pkt.ipi6_ifindex; | 438 | np->sticky_pktinfo.ipi6_ifindex = pkt.ipi6_ifindex; |
439 | np->sticky_pktinfo.ipi6_addr = pkt.ipi6_addr; | 439 | np->sticky_pktinfo.ipi6_addr = pkt.ipi6_addr; |
440 | retv = 0; | 440 | retv = 0; |
441 | break; | 441 | break; |
442 | } | 442 | } |
443 | 443 | ||
444 | case IPV6_2292PKTOPTIONS: | 444 | case IPV6_2292PKTOPTIONS: |
445 | { | 445 | { |
446 | struct ipv6_txoptions *opt = NULL; | 446 | struct ipv6_txoptions *opt = NULL; |
447 | struct msghdr msg; | 447 | struct msghdr msg; |
448 | struct flowi6 fl6; | 448 | struct flowi6 fl6; |
449 | int junk; | 449 | int junk; |
450 | 450 | ||
451 | memset(&fl6, 0, sizeof(fl6)); | 451 | memset(&fl6, 0, sizeof(fl6)); |
452 | fl6.flowi6_oif = sk->sk_bound_dev_if; | 452 | fl6.flowi6_oif = sk->sk_bound_dev_if; |
453 | fl6.flowi6_mark = sk->sk_mark; | 453 | fl6.flowi6_mark = sk->sk_mark; |
454 | 454 | ||
455 | if (optlen == 0) | 455 | if (optlen == 0) |
456 | goto update; | 456 | goto update; |
457 | 457 | ||
458 | /* 1K is probably excessive | 458 | /* 1K is probably excessive |
459 | * 1K is surely not enough, 2K per standard header is 16K. | 459 | * 1K is surely not enough, 2K per standard header is 16K. |
460 | */ | 460 | */ |
461 | retv = -EINVAL; | 461 | retv = -EINVAL; |
462 | if (optlen > 64*1024) | 462 | if (optlen > 64*1024) |
463 | break; | 463 | break; |
464 | 464 | ||
465 | opt = sock_kmalloc(sk, sizeof(*opt) + optlen, GFP_KERNEL); | 465 | opt = sock_kmalloc(sk, sizeof(*opt) + optlen, GFP_KERNEL); |
466 | retv = -ENOBUFS; | 466 | retv = -ENOBUFS; |
467 | if (opt == NULL) | 467 | if (opt == NULL) |
468 | break; | 468 | break; |
469 | 469 | ||
470 | memset(opt, 0, sizeof(*opt)); | 470 | memset(opt, 0, sizeof(*opt)); |
471 | opt->tot_len = sizeof(*opt) + optlen; | 471 | opt->tot_len = sizeof(*opt) + optlen; |
472 | retv = -EFAULT; | 472 | retv = -EFAULT; |
473 | if (copy_from_user(opt+1, optval, optlen)) | 473 | if (copy_from_user(opt+1, optval, optlen)) |
474 | goto done; | 474 | goto done; |
475 | 475 | ||
476 | msg.msg_controllen = optlen; | 476 | msg.msg_controllen = optlen; |
477 | msg.msg_control = (void*)(opt+1); | 477 | msg.msg_control = (void*)(opt+1); |
478 | 478 | ||
479 | retv = ip6_datagram_send_ctl(net, sk, &msg, &fl6, opt, &junk, | 479 | retv = ip6_datagram_send_ctl(net, sk, &msg, &fl6, opt, &junk, |
480 | &junk, &junk); | 480 | &junk, &junk); |
481 | if (retv) | 481 | if (retv) |
482 | goto done; | 482 | goto done; |
483 | update: | 483 | update: |
484 | retv = 0; | 484 | retv = 0; |
485 | opt = ipv6_update_options(sk, opt); | 485 | opt = ipv6_update_options(sk, opt); |
486 | done: | 486 | done: |
487 | if (opt) | 487 | if (opt) |
488 | sock_kfree_s(sk, opt, opt->tot_len); | 488 | sock_kfree_s(sk, opt, opt->tot_len); |
489 | break; | 489 | break; |
490 | } | 490 | } |
491 | case IPV6_UNICAST_HOPS: | 491 | case IPV6_UNICAST_HOPS: |
492 | if (optlen < sizeof(int)) | 492 | if (optlen < sizeof(int)) |
493 | goto e_inval; | 493 | goto e_inval; |
494 | if (val > 255 || val < -1) | 494 | if (val > 255 || val < -1) |
495 | goto e_inval; | 495 | goto e_inval; |
496 | np->hop_limit = val; | 496 | np->hop_limit = val; |
497 | retv = 0; | 497 | retv = 0; |
498 | break; | 498 | break; |
499 | 499 | ||
500 | case IPV6_MULTICAST_HOPS: | 500 | case IPV6_MULTICAST_HOPS: |
501 | if (sk->sk_type == SOCK_STREAM) | 501 | if (sk->sk_type == SOCK_STREAM) |
502 | break; | 502 | break; |
503 | if (optlen < sizeof(int)) | 503 | if (optlen < sizeof(int)) |
504 | goto e_inval; | 504 | goto e_inval; |
505 | if (val > 255 || val < -1) | 505 | if (val > 255 || val < -1) |
506 | goto e_inval; | 506 | goto e_inval; |
507 | np->mcast_hops = (val == -1 ? IPV6_DEFAULT_MCASTHOPS : val); | 507 | np->mcast_hops = (val == -1 ? IPV6_DEFAULT_MCASTHOPS : val); |
508 | retv = 0; | 508 | retv = 0; |
509 | break; | 509 | break; |
510 | 510 | ||
511 | case IPV6_MULTICAST_LOOP: | 511 | case IPV6_MULTICAST_LOOP: |
512 | if (optlen < sizeof(int)) | 512 | if (optlen < sizeof(int)) |
513 | goto e_inval; | 513 | goto e_inval; |
514 | if (val != valbool) | 514 | if (val != valbool) |
515 | goto e_inval; | 515 | goto e_inval; |
516 | np->mc_loop = valbool; | 516 | np->mc_loop = valbool; |
517 | retv = 0; | 517 | retv = 0; |
518 | break; | 518 | break; |
519 | 519 | ||
520 | case IPV6_UNICAST_IF: | 520 | case IPV6_UNICAST_IF: |
521 | { | 521 | { |
522 | struct net_device *dev = NULL; | 522 | struct net_device *dev = NULL; |
523 | int ifindex; | 523 | int ifindex; |
524 | 524 | ||
525 | if (optlen != sizeof(int)) | 525 | if (optlen != sizeof(int)) |
526 | goto e_inval; | 526 | goto e_inval; |
527 | 527 | ||
528 | ifindex = (__force int)ntohl((__force __be32)val); | 528 | ifindex = (__force int)ntohl((__force __be32)val); |
529 | if (ifindex == 0) { | 529 | if (ifindex == 0) { |
530 | np->ucast_oif = 0; | 530 | np->ucast_oif = 0; |
531 | retv = 0; | 531 | retv = 0; |
532 | break; | 532 | break; |
533 | } | 533 | } |
534 | 534 | ||
535 | dev = dev_get_by_index(net, ifindex); | 535 | dev = dev_get_by_index(net, ifindex); |
536 | retv = -EADDRNOTAVAIL; | 536 | retv = -EADDRNOTAVAIL; |
537 | if (!dev) | 537 | if (!dev) |
538 | break; | 538 | break; |
539 | dev_put(dev); | 539 | dev_put(dev); |
540 | 540 | ||
541 | retv = -EINVAL; | 541 | retv = -EINVAL; |
542 | if (sk->sk_bound_dev_if) | 542 | if (sk->sk_bound_dev_if) |
543 | break; | 543 | break; |
544 | 544 | ||
545 | np->ucast_oif = ifindex; | 545 | np->ucast_oif = ifindex; |
546 | retv = 0; | 546 | retv = 0; |
547 | break; | 547 | break; |
548 | } | 548 | } |
549 | 549 | ||
550 | case IPV6_MULTICAST_IF: | 550 | case IPV6_MULTICAST_IF: |
551 | if (sk->sk_type == SOCK_STREAM) | 551 | if (sk->sk_type == SOCK_STREAM) |
552 | break; | 552 | break; |
553 | if (optlen < sizeof(int)) | 553 | if (optlen < sizeof(int)) |
554 | goto e_inval; | 554 | goto e_inval; |
555 | 555 | ||
556 | if (val) { | 556 | if (val) { |
557 | struct net_device *dev; | 557 | struct net_device *dev; |
558 | 558 | ||
559 | if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val) | 559 | if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val) |
560 | goto e_inval; | 560 | goto e_inval; |
561 | 561 | ||
562 | dev = dev_get_by_index(net, val); | 562 | dev = dev_get_by_index(net, val); |
563 | if (!dev) { | 563 | if (!dev) { |
564 | retv = -ENODEV; | 564 | retv = -ENODEV; |
565 | break; | 565 | break; |
566 | } | 566 | } |
567 | dev_put(dev); | 567 | dev_put(dev); |
568 | } | 568 | } |
569 | np->mcast_oif = val; | 569 | np->mcast_oif = val; |
570 | retv = 0; | 570 | retv = 0; |
571 | break; | 571 | break; |
572 | case IPV6_ADD_MEMBERSHIP: | 572 | case IPV6_ADD_MEMBERSHIP: |
573 | case IPV6_DROP_MEMBERSHIP: | 573 | case IPV6_DROP_MEMBERSHIP: |
574 | { | 574 | { |
575 | struct ipv6_mreq mreq; | 575 | struct ipv6_mreq mreq; |
576 | 576 | ||
577 | if (optlen < sizeof(struct ipv6_mreq)) | 577 | if (optlen < sizeof(struct ipv6_mreq)) |
578 | goto e_inval; | 578 | goto e_inval; |
579 | 579 | ||
580 | retv = -EPROTO; | 580 | retv = -EPROTO; |
581 | if (inet_sk(sk)->is_icsk) | 581 | if (inet_sk(sk)->is_icsk) |
582 | break; | 582 | break; |
583 | 583 | ||
584 | retv = -EFAULT; | 584 | retv = -EFAULT; |
585 | if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq))) | 585 | if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq))) |
586 | break; | 586 | break; |
587 | 587 | ||
588 | if (optname == IPV6_ADD_MEMBERSHIP) | 588 | if (optname == IPV6_ADD_MEMBERSHIP) |
589 | retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr); | 589 | retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr); |
590 | else | 590 | else |
591 | retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr); | 591 | retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr); |
592 | break; | 592 | break; |
593 | } | 593 | } |
594 | case IPV6_JOIN_ANYCAST: | 594 | case IPV6_JOIN_ANYCAST: |
595 | case IPV6_LEAVE_ANYCAST: | 595 | case IPV6_LEAVE_ANYCAST: |
596 | { | 596 | { |
597 | struct ipv6_mreq mreq; | 597 | struct ipv6_mreq mreq; |
598 | 598 | ||
599 | if (optlen < sizeof(struct ipv6_mreq)) | 599 | if (optlen < sizeof(struct ipv6_mreq)) |
600 | goto e_inval; | 600 | goto e_inval; |
601 | 601 | ||
602 | retv = -EFAULT; | 602 | retv = -EFAULT; |
603 | if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq))) | 603 | if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq))) |
604 | break; | 604 | break; |
605 | 605 | ||
606 | if (optname == IPV6_JOIN_ANYCAST) | 606 | if (optname == IPV6_JOIN_ANYCAST) |
607 | retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr); | 607 | retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr); |
608 | else | 608 | else |
609 | retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr); | 609 | retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr); |
610 | break; | 610 | break; |
611 | } | 611 | } |
612 | case MCAST_JOIN_GROUP: | 612 | case MCAST_JOIN_GROUP: |
613 | case MCAST_LEAVE_GROUP: | 613 | case MCAST_LEAVE_GROUP: |
614 | { | 614 | { |
615 | struct group_req greq; | 615 | struct group_req greq; |
616 | struct sockaddr_in6 *psin6; | 616 | struct sockaddr_in6 *psin6; |
617 | 617 | ||
618 | if (optlen < sizeof(struct group_req)) | 618 | if (optlen < sizeof(struct group_req)) |
619 | goto e_inval; | 619 | goto e_inval; |
620 | 620 | ||
621 | retv = -EFAULT; | 621 | retv = -EFAULT; |
622 | if (copy_from_user(&greq, optval, sizeof(struct group_req))) | 622 | if (copy_from_user(&greq, optval, sizeof(struct group_req))) |
623 | break; | 623 | break; |
624 | if (greq.gr_group.ss_family != AF_INET6) { | 624 | if (greq.gr_group.ss_family != AF_INET6) { |
625 | retv = -EADDRNOTAVAIL; | 625 | retv = -EADDRNOTAVAIL; |
626 | break; | 626 | break; |
627 | } | 627 | } |
628 | psin6 = (struct sockaddr_in6 *)&greq.gr_group; | 628 | psin6 = (struct sockaddr_in6 *)&greq.gr_group; |
629 | if (optname == MCAST_JOIN_GROUP) | 629 | if (optname == MCAST_JOIN_GROUP) |
630 | retv = ipv6_sock_mc_join(sk, greq.gr_interface, | 630 | retv = ipv6_sock_mc_join(sk, greq.gr_interface, |
631 | &psin6->sin6_addr); | 631 | &psin6->sin6_addr); |
632 | else | 632 | else |
633 | retv = ipv6_sock_mc_drop(sk, greq.gr_interface, | 633 | retv = ipv6_sock_mc_drop(sk, greq.gr_interface, |
634 | &psin6->sin6_addr); | 634 | &psin6->sin6_addr); |
635 | break; | 635 | break; |
636 | } | 636 | } |
637 | case MCAST_JOIN_SOURCE_GROUP: | 637 | case MCAST_JOIN_SOURCE_GROUP: |
638 | case MCAST_LEAVE_SOURCE_GROUP: | 638 | case MCAST_LEAVE_SOURCE_GROUP: |
639 | case MCAST_BLOCK_SOURCE: | 639 | case MCAST_BLOCK_SOURCE: |
640 | case MCAST_UNBLOCK_SOURCE: | 640 | case MCAST_UNBLOCK_SOURCE: |
641 | { | 641 | { |
642 | struct group_source_req greqs; | 642 | struct group_source_req greqs; |
643 | int omode, add; | 643 | int omode, add; |
644 | 644 | ||
645 | if (optlen < sizeof(struct group_source_req)) | 645 | if (optlen < sizeof(struct group_source_req)) |
646 | goto e_inval; | 646 | goto e_inval; |
647 | if (copy_from_user(&greqs, optval, sizeof(greqs))) { | 647 | if (copy_from_user(&greqs, optval, sizeof(greqs))) { |
648 | retv = -EFAULT; | 648 | retv = -EFAULT; |
649 | break; | 649 | break; |
650 | } | 650 | } |
651 | if (greqs.gsr_group.ss_family != AF_INET6 || | 651 | if (greqs.gsr_group.ss_family != AF_INET6 || |
652 | greqs.gsr_source.ss_family != AF_INET6) { | 652 | greqs.gsr_source.ss_family != AF_INET6) { |
653 | retv = -EADDRNOTAVAIL; | 653 | retv = -EADDRNOTAVAIL; |
654 | break; | 654 | break; |
655 | } | 655 | } |
656 | if (optname == MCAST_BLOCK_SOURCE) { | 656 | if (optname == MCAST_BLOCK_SOURCE) { |
657 | omode = MCAST_EXCLUDE; | 657 | omode = MCAST_EXCLUDE; |
658 | add = 1; | 658 | add = 1; |
659 | } else if (optname == MCAST_UNBLOCK_SOURCE) { | 659 | } else if (optname == MCAST_UNBLOCK_SOURCE) { |
660 | omode = MCAST_EXCLUDE; | 660 | omode = MCAST_EXCLUDE; |
661 | add = 0; | 661 | add = 0; |
662 | } else if (optname == MCAST_JOIN_SOURCE_GROUP) { | 662 | } else if (optname == MCAST_JOIN_SOURCE_GROUP) { |
663 | struct sockaddr_in6 *psin6; | 663 | struct sockaddr_in6 *psin6; |
664 | 664 | ||
665 | psin6 = (struct sockaddr_in6 *)&greqs.gsr_group; | 665 | psin6 = (struct sockaddr_in6 *)&greqs.gsr_group; |
666 | retv = ipv6_sock_mc_join(sk, greqs.gsr_interface, | 666 | retv = ipv6_sock_mc_join(sk, greqs.gsr_interface, |
667 | &psin6->sin6_addr); | 667 | &psin6->sin6_addr); |
668 | /* prior join w/ different source is ok */ | 668 | /* prior join w/ different source is ok */ |
669 | if (retv && retv != -EADDRINUSE) | 669 | if (retv && retv != -EADDRINUSE) |
670 | break; | 670 | break; |
671 | omode = MCAST_INCLUDE; | 671 | omode = MCAST_INCLUDE; |
672 | add = 1; | 672 | add = 1; |
673 | } else /* MCAST_LEAVE_SOURCE_GROUP */ { | 673 | } else /* MCAST_LEAVE_SOURCE_GROUP */ { |
674 | omode = MCAST_INCLUDE; | 674 | omode = MCAST_INCLUDE; |
675 | add = 0; | 675 | add = 0; |
676 | } | 676 | } |
677 | retv = ip6_mc_source(add, omode, sk, &greqs); | 677 | retv = ip6_mc_source(add, omode, sk, &greqs); |
678 | break; | 678 | break; |
679 | } | 679 | } |
680 | case MCAST_MSFILTER: | 680 | case MCAST_MSFILTER: |
681 | { | 681 | { |
682 | struct group_filter *gsf; | 682 | struct group_filter *gsf; |
683 | 683 | ||
684 | if (optlen < GROUP_FILTER_SIZE(0)) | 684 | if (optlen < GROUP_FILTER_SIZE(0)) |
685 | goto e_inval; | 685 | goto e_inval; |
686 | if (optlen > sysctl_optmem_max) { | 686 | if (optlen > sysctl_optmem_max) { |
687 | retv = -ENOBUFS; | 687 | retv = -ENOBUFS; |
688 | break; | 688 | break; |
689 | } | 689 | } |
690 | gsf = kmalloc(optlen,GFP_KERNEL); | 690 | gsf = kmalloc(optlen,GFP_KERNEL); |
691 | if (!gsf) { | 691 | if (!gsf) { |
692 | retv = -ENOBUFS; | 692 | retv = -ENOBUFS; |
693 | break; | 693 | break; |
694 | } | 694 | } |
695 | retv = -EFAULT; | 695 | retv = -EFAULT; |
696 | if (copy_from_user(gsf, optval, optlen)) { | 696 | if (copy_from_user(gsf, optval, optlen)) { |
697 | kfree(gsf); | 697 | kfree(gsf); |
698 | break; | 698 | break; |
699 | } | 699 | } |
700 | /* numsrc >= (4G-140)/128 overflow in 32 bits */ | 700 | /* numsrc >= (4G-140)/128 overflow in 32 bits */ |
701 | if (gsf->gf_numsrc >= 0x1ffffffU || | 701 | if (gsf->gf_numsrc >= 0x1ffffffU || |
702 | gsf->gf_numsrc > sysctl_mld_max_msf) { | 702 | gsf->gf_numsrc > sysctl_mld_max_msf) { |
703 | kfree(gsf); | 703 | kfree(gsf); |
704 | retv = -ENOBUFS; | 704 | retv = -ENOBUFS; |
705 | break; | 705 | break; |
706 | } | 706 | } |
707 | if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) { | 707 | if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) { |
708 | kfree(gsf); | 708 | kfree(gsf); |
709 | retv = -EINVAL; | 709 | retv = -EINVAL; |
710 | break; | 710 | break; |
711 | } | 711 | } |
712 | retv = ip6_mc_msfilter(sk, gsf); | 712 | retv = ip6_mc_msfilter(sk, gsf); |
713 | kfree(gsf); | 713 | kfree(gsf); |
714 | 714 | ||
715 | break; | 715 | break; |
716 | } | 716 | } |
717 | case IPV6_ROUTER_ALERT: | 717 | case IPV6_ROUTER_ALERT: |
718 | if (optlen < sizeof(int)) | 718 | if (optlen < sizeof(int)) |
719 | goto e_inval; | 719 | goto e_inval; |
720 | retv = ip6_ra_control(sk, val); | 720 | retv = ip6_ra_control(sk, val); |
721 | break; | 721 | break; |
722 | case IPV6_MTU_DISCOVER: | 722 | case IPV6_MTU_DISCOVER: |
723 | if (optlen < sizeof(int)) | 723 | if (optlen < sizeof(int)) |
724 | goto e_inval; | 724 | goto e_inval; |
725 | if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE) | 725 | if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE) |
726 | goto e_inval; | 726 | goto e_inval; |
727 | np->pmtudisc = val; | 727 | np->pmtudisc = val; |
728 | retv = 0; | 728 | retv = 0; |
729 | break; | 729 | break; |
730 | case IPV6_MTU: | 730 | case IPV6_MTU: |
731 | if (optlen < sizeof(int)) | 731 | if (optlen < sizeof(int)) |
732 | goto e_inval; | 732 | goto e_inval; |
733 | if (val && val < IPV6_MIN_MTU) | 733 | if (val && val < IPV6_MIN_MTU) |
734 | goto e_inval; | 734 | goto e_inval; |
735 | np->frag_size = val; | 735 | np->frag_size = val; |
736 | retv = 0; | 736 | retv = 0; |
737 | break; | 737 | break; |
738 | case IPV6_RECVERR: | 738 | case IPV6_RECVERR: |
739 | if (optlen < sizeof(int)) | 739 | if (optlen < sizeof(int)) |
740 | goto e_inval; | 740 | goto e_inval; |
741 | np->recverr = valbool; | 741 | np->recverr = valbool; |
742 | if (!val) | 742 | if (!val) |
743 | skb_queue_purge(&sk->sk_error_queue); | 743 | skb_queue_purge(&sk->sk_error_queue); |
744 | retv = 0; | 744 | retv = 0; |
745 | break; | 745 | break; |
746 | case IPV6_FLOWINFO_SEND: | 746 | case IPV6_FLOWINFO_SEND: |
747 | if (optlen < sizeof(int)) | 747 | if (optlen < sizeof(int)) |
748 | goto e_inval; | 748 | goto e_inval; |
749 | np->sndflow = valbool; | 749 | np->sndflow = valbool; |
750 | retv = 0; | 750 | retv = 0; |
751 | break; | 751 | break; |
752 | case IPV6_FLOWLABEL_MGR: | 752 | case IPV6_FLOWLABEL_MGR: |
753 | retv = ipv6_flowlabel_opt(sk, optval, optlen); | 753 | retv = ipv6_flowlabel_opt(sk, optval, optlen); |
754 | break; | 754 | break; |
755 | case IPV6_IPSEC_POLICY: | 755 | case IPV6_IPSEC_POLICY: |
756 | case IPV6_XFRM_POLICY: | 756 | case IPV6_XFRM_POLICY: |
757 | retv = -EPERM; | 757 | retv = -EPERM; |
758 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) | 758 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
759 | break; | 759 | break; |
760 | retv = xfrm_user_policy(sk, optname, optval, optlen); | 760 | retv = xfrm_user_policy(sk, optname, optval, optlen); |
761 | break; | 761 | break; |
762 | 762 | ||
763 | case IPV6_ADDR_PREFERENCES: | 763 | case IPV6_ADDR_PREFERENCES: |
764 | { | 764 | { |
765 | unsigned int pref = 0; | 765 | unsigned int pref = 0; |
766 | unsigned int prefmask = ~0; | 766 | unsigned int prefmask = ~0; |
767 | 767 | ||
768 | if (optlen < sizeof(int)) | 768 | if (optlen < sizeof(int)) |
769 | goto e_inval; | 769 | goto e_inval; |
770 | 770 | ||
771 | retv = -EINVAL; | 771 | retv = -EINVAL; |
772 | 772 | ||
773 | /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */ | 773 | /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */ |
774 | switch (val & (IPV6_PREFER_SRC_PUBLIC| | 774 | switch (val & (IPV6_PREFER_SRC_PUBLIC| |
775 | IPV6_PREFER_SRC_TMP| | 775 | IPV6_PREFER_SRC_TMP| |
776 | IPV6_PREFER_SRC_PUBTMP_DEFAULT)) { | 776 | IPV6_PREFER_SRC_PUBTMP_DEFAULT)) { |
777 | case IPV6_PREFER_SRC_PUBLIC: | 777 | case IPV6_PREFER_SRC_PUBLIC: |
778 | pref |= IPV6_PREFER_SRC_PUBLIC; | 778 | pref |= IPV6_PREFER_SRC_PUBLIC; |
779 | break; | 779 | break; |
780 | case IPV6_PREFER_SRC_TMP: | 780 | case IPV6_PREFER_SRC_TMP: |
781 | pref |= IPV6_PREFER_SRC_TMP; | 781 | pref |= IPV6_PREFER_SRC_TMP; |
782 | break; | 782 | break; |
783 | case IPV6_PREFER_SRC_PUBTMP_DEFAULT: | 783 | case IPV6_PREFER_SRC_PUBTMP_DEFAULT: |
784 | break; | 784 | break; |
785 | case 0: | 785 | case 0: |
786 | goto pref_skip_pubtmp; | 786 | goto pref_skip_pubtmp; |
787 | default: | 787 | default: |
788 | goto e_inval; | 788 | goto e_inval; |
789 | } | 789 | } |
790 | 790 | ||
791 | prefmask &= ~(IPV6_PREFER_SRC_PUBLIC| | 791 | prefmask &= ~(IPV6_PREFER_SRC_PUBLIC| |
792 | IPV6_PREFER_SRC_TMP); | 792 | IPV6_PREFER_SRC_TMP); |
793 | pref_skip_pubtmp: | 793 | pref_skip_pubtmp: |
794 | 794 | ||
795 | /* check HOME/COA conflicts */ | 795 | /* check HOME/COA conflicts */ |
796 | switch (val & (IPV6_PREFER_SRC_HOME|IPV6_PREFER_SRC_COA)) { | 796 | switch (val & (IPV6_PREFER_SRC_HOME|IPV6_PREFER_SRC_COA)) { |
797 | case IPV6_PREFER_SRC_HOME: | 797 | case IPV6_PREFER_SRC_HOME: |
798 | break; | 798 | break; |
799 | case IPV6_PREFER_SRC_COA: | 799 | case IPV6_PREFER_SRC_COA: |
800 | pref |= IPV6_PREFER_SRC_COA; | 800 | pref |= IPV6_PREFER_SRC_COA; |
801 | case 0: | 801 | case 0: |
802 | goto pref_skip_coa; | 802 | goto pref_skip_coa; |
803 | default: | 803 | default: |
804 | goto e_inval; | 804 | goto e_inval; |
805 | } | 805 | } |
806 | 806 | ||
807 | prefmask &= ~IPV6_PREFER_SRC_COA; | 807 | prefmask &= ~IPV6_PREFER_SRC_COA; |
808 | pref_skip_coa: | 808 | pref_skip_coa: |
809 | 809 | ||
810 | /* check CGA/NONCGA conflicts */ | 810 | /* check CGA/NONCGA conflicts */ |
811 | switch (val & (IPV6_PREFER_SRC_CGA|IPV6_PREFER_SRC_NONCGA)) { | 811 | switch (val & (IPV6_PREFER_SRC_CGA|IPV6_PREFER_SRC_NONCGA)) { |
812 | case IPV6_PREFER_SRC_CGA: | 812 | case IPV6_PREFER_SRC_CGA: |
813 | case IPV6_PREFER_SRC_NONCGA: | 813 | case IPV6_PREFER_SRC_NONCGA: |
814 | case 0: | 814 | case 0: |
815 | break; | 815 | break; |
816 | default: | 816 | default: |
817 | goto e_inval; | 817 | goto e_inval; |
818 | } | 818 | } |
819 | 819 | ||
820 | np->srcprefs = (np->srcprefs & prefmask) | pref; | 820 | np->srcprefs = (np->srcprefs & prefmask) | pref; |
821 | retv = 0; | 821 | retv = 0; |
822 | 822 | ||
823 | break; | 823 | break; |
824 | } | 824 | } |
825 | case IPV6_MINHOPCOUNT: | 825 | case IPV6_MINHOPCOUNT: |
826 | if (optlen < sizeof(int)) | 826 | if (optlen < sizeof(int)) |
827 | goto e_inval; | 827 | goto e_inval; |
828 | if (val < 0 || val > 255) | 828 | if (val < 0 || val > 255) |
829 | goto e_inval; | 829 | goto e_inval; |
830 | np->min_hopcount = val; | 830 | np->min_hopcount = val; |
831 | retv = 0; | 831 | retv = 0; |
832 | break; | 832 | break; |
833 | case IPV6_DONTFRAG: | 833 | case IPV6_DONTFRAG: |
834 | np->dontfrag = valbool; | 834 | np->dontfrag = valbool; |
835 | retv = 0; | 835 | retv = 0; |
836 | break; | 836 | break; |
837 | } | 837 | } |
838 | 838 | ||
839 | release_sock(sk); | 839 | release_sock(sk); |
840 | 840 | ||
841 | return retv; | 841 | return retv; |
842 | 842 | ||
843 | e_inval: | 843 | e_inval: |
844 | release_sock(sk); | 844 | release_sock(sk); |
845 | return -EINVAL; | 845 | return -EINVAL; |
846 | } | 846 | } |
847 | 847 | ||
848 | int ipv6_setsockopt(struct sock *sk, int level, int optname, | 848 | int ipv6_setsockopt(struct sock *sk, int level, int optname, |
849 | char __user *optval, unsigned int optlen) | 849 | char __user *optval, unsigned int optlen) |
850 | { | 850 | { |
851 | int err; | 851 | int err; |
852 | 852 | ||
853 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) | 853 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) |
854 | return udp_prot.setsockopt(sk, level, optname, optval, optlen); | 854 | return udp_prot.setsockopt(sk, level, optname, optval, optlen); |
855 | 855 | ||
856 | if (level != SOL_IPV6) | 856 | if (level != SOL_IPV6) |
857 | return -ENOPROTOOPT; | 857 | return -ENOPROTOOPT; |
858 | 858 | ||
859 | err = do_ipv6_setsockopt(sk, level, optname, optval, optlen); | 859 | err = do_ipv6_setsockopt(sk, level, optname, optval, optlen); |
860 | #ifdef CONFIG_NETFILTER | 860 | #ifdef CONFIG_NETFILTER |
861 | /* we need to exclude all possible ENOPROTOOPTs except default case */ | 861 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
862 | if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY && | 862 | if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY && |
863 | optname != IPV6_XFRM_POLICY) { | 863 | optname != IPV6_XFRM_POLICY) { |
864 | lock_sock(sk); | 864 | lock_sock(sk); |
865 | err = nf_setsockopt(sk, PF_INET6, optname, optval, | 865 | err = nf_setsockopt(sk, PF_INET6, optname, optval, |
866 | optlen); | 866 | optlen); |
867 | release_sock(sk); | 867 | release_sock(sk); |
868 | } | 868 | } |
869 | #endif | 869 | #endif |
870 | return err; | 870 | return err; |
871 | } | 871 | } |
872 | 872 | ||
873 | EXPORT_SYMBOL(ipv6_setsockopt); | 873 | EXPORT_SYMBOL(ipv6_setsockopt); |
874 | 874 | ||
875 | #ifdef CONFIG_COMPAT | 875 | #ifdef CONFIG_COMPAT |
876 | int compat_ipv6_setsockopt(struct sock *sk, int level, int optname, | 876 | int compat_ipv6_setsockopt(struct sock *sk, int level, int optname, |
877 | char __user *optval, unsigned int optlen) | 877 | char __user *optval, unsigned int optlen) |
878 | { | 878 | { |
879 | int err; | 879 | int err; |
880 | 880 | ||
881 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) { | 881 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) { |
882 | if (udp_prot.compat_setsockopt != NULL) | 882 | if (udp_prot.compat_setsockopt != NULL) |
883 | return udp_prot.compat_setsockopt(sk, level, optname, | 883 | return udp_prot.compat_setsockopt(sk, level, optname, |
884 | optval, optlen); | 884 | optval, optlen); |
885 | return udp_prot.setsockopt(sk, level, optname, optval, optlen); | 885 | return udp_prot.setsockopt(sk, level, optname, optval, optlen); |
886 | } | 886 | } |
887 | 887 | ||
888 | if (level != SOL_IPV6) | 888 | if (level != SOL_IPV6) |
889 | return -ENOPROTOOPT; | 889 | return -ENOPROTOOPT; |
890 | 890 | ||
891 | if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER) | 891 | if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER) |
892 | return compat_mc_setsockopt(sk, level, optname, optval, optlen, | 892 | return compat_mc_setsockopt(sk, level, optname, optval, optlen, |
893 | ipv6_setsockopt); | 893 | ipv6_setsockopt); |
894 | 894 | ||
895 | err = do_ipv6_setsockopt(sk, level, optname, optval, optlen); | 895 | err = do_ipv6_setsockopt(sk, level, optname, optval, optlen); |
896 | #ifdef CONFIG_NETFILTER | 896 | #ifdef CONFIG_NETFILTER |
897 | /* we need to exclude all possible ENOPROTOOPTs except default case */ | 897 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
898 | if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY && | 898 | if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY && |
899 | optname != IPV6_XFRM_POLICY) { | 899 | optname != IPV6_XFRM_POLICY) { |
900 | lock_sock(sk); | 900 | lock_sock(sk); |
901 | err = compat_nf_setsockopt(sk, PF_INET6, optname, | 901 | err = compat_nf_setsockopt(sk, PF_INET6, optname, |
902 | optval, optlen); | 902 | optval, optlen); |
903 | release_sock(sk); | 903 | release_sock(sk); |
904 | } | 904 | } |
905 | #endif | 905 | #endif |
906 | return err; | 906 | return err; |
907 | } | 907 | } |
908 | 908 | ||
909 | EXPORT_SYMBOL(compat_ipv6_setsockopt); | 909 | EXPORT_SYMBOL(compat_ipv6_setsockopt); |
910 | #endif | 910 | #endif |
911 | 911 | ||
912 | static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt, | 912 | static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt, |
913 | int optname, char __user *optval, int len) | 913 | int optname, char __user *optval, int len) |
914 | { | 914 | { |
915 | struct ipv6_opt_hdr *hdr; | 915 | struct ipv6_opt_hdr *hdr; |
916 | 916 | ||
917 | if (!opt) | 917 | if (!opt) |
918 | return 0; | 918 | return 0; |
919 | 919 | ||
920 | switch(optname) { | 920 | switch(optname) { |
921 | case IPV6_HOPOPTS: | 921 | case IPV6_HOPOPTS: |
922 | hdr = opt->hopopt; | 922 | hdr = opt->hopopt; |
923 | break; | 923 | break; |
924 | case IPV6_RTHDRDSTOPTS: | 924 | case IPV6_RTHDRDSTOPTS: |
925 | hdr = opt->dst0opt; | 925 | hdr = opt->dst0opt; |
926 | break; | 926 | break; |
927 | case IPV6_RTHDR: | 927 | case IPV6_RTHDR: |
928 | hdr = (struct ipv6_opt_hdr *)opt->srcrt; | 928 | hdr = (struct ipv6_opt_hdr *)opt->srcrt; |
929 | break; | 929 | break; |
930 | case IPV6_DSTOPTS: | 930 | case IPV6_DSTOPTS: |
931 | hdr = opt->dst1opt; | 931 | hdr = opt->dst1opt; |
932 | break; | 932 | break; |
933 | default: | 933 | default: |
934 | return -EINVAL; /* should not happen */ | 934 | return -EINVAL; /* should not happen */ |
935 | } | 935 | } |
936 | 936 | ||
937 | if (!hdr) | 937 | if (!hdr) |
938 | return 0; | 938 | return 0; |
939 | 939 | ||
940 | len = min_t(unsigned int, len, ipv6_optlen(hdr)); | 940 | len = min_t(unsigned int, len, ipv6_optlen(hdr)); |
941 | if (copy_to_user(optval, hdr, len)) | 941 | if (copy_to_user(optval, hdr, len)) |
942 | return -EFAULT; | 942 | return -EFAULT; |
943 | return len; | 943 | return len; |
944 | } | 944 | } |
945 | 945 | ||
946 | static int do_ipv6_getsockopt(struct sock *sk, int level, int optname, | 946 | static int do_ipv6_getsockopt(struct sock *sk, int level, int optname, |
947 | char __user *optval, int __user *optlen, unsigned int flags) | 947 | char __user *optval, int __user *optlen, unsigned int flags) |
948 | { | 948 | { |
949 | struct ipv6_pinfo *np = inet6_sk(sk); | 949 | struct ipv6_pinfo *np = inet6_sk(sk); |
950 | int len; | 950 | int len; |
951 | int val; | 951 | int val; |
952 | 952 | ||
953 | if (ip6_mroute_opt(optname)) | 953 | if (ip6_mroute_opt(optname)) |
954 | return ip6_mroute_getsockopt(sk, optname, optval, optlen); | 954 | return ip6_mroute_getsockopt(sk, optname, optval, optlen); |
955 | 955 | ||
956 | if (get_user(len, optlen)) | 956 | if (get_user(len, optlen)) |
957 | return -EFAULT; | 957 | return -EFAULT; |
958 | switch (optname) { | 958 | switch (optname) { |
959 | case IPV6_ADDRFORM: | 959 | case IPV6_ADDRFORM: |
960 | if (sk->sk_protocol != IPPROTO_UDP && | 960 | if (sk->sk_protocol != IPPROTO_UDP && |
961 | sk->sk_protocol != IPPROTO_UDPLITE && | 961 | sk->sk_protocol != IPPROTO_UDPLITE && |
962 | sk->sk_protocol != IPPROTO_TCP) | 962 | sk->sk_protocol != IPPROTO_TCP) |
963 | return -ENOPROTOOPT; | 963 | return -ENOPROTOOPT; |
964 | if (sk->sk_state != TCP_ESTABLISHED) | 964 | if (sk->sk_state != TCP_ESTABLISHED) |
965 | return -ENOTCONN; | 965 | return -ENOTCONN; |
966 | val = sk->sk_family; | 966 | val = sk->sk_family; |
967 | break; | 967 | break; |
968 | case MCAST_MSFILTER: | 968 | case MCAST_MSFILTER: |
969 | { | 969 | { |
970 | struct group_filter gsf; | 970 | struct group_filter gsf; |
971 | int err; | 971 | int err; |
972 | 972 | ||
973 | if (len < GROUP_FILTER_SIZE(0)) | 973 | if (len < GROUP_FILTER_SIZE(0)) |
974 | return -EINVAL; | 974 | return -EINVAL; |
975 | if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0))) | 975 | if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0))) |
976 | return -EFAULT; | 976 | return -EFAULT; |
977 | if (gsf.gf_group.ss_family != AF_INET6) | 977 | if (gsf.gf_group.ss_family != AF_INET6) |
978 | return -EADDRNOTAVAIL; | 978 | return -EADDRNOTAVAIL; |
979 | lock_sock(sk); | 979 | lock_sock(sk); |
980 | err = ip6_mc_msfget(sk, &gsf, | 980 | err = ip6_mc_msfget(sk, &gsf, |
981 | (struct group_filter __user *)optval, optlen); | 981 | (struct group_filter __user *)optval, optlen); |
982 | release_sock(sk); | 982 | release_sock(sk); |
983 | return err; | 983 | return err; |
984 | } | 984 | } |
985 | 985 | ||
986 | case IPV6_2292PKTOPTIONS: | 986 | case IPV6_2292PKTOPTIONS: |
987 | { | 987 | { |
988 | struct msghdr msg; | 988 | struct msghdr msg; |
989 | struct sk_buff *skb; | 989 | struct sk_buff *skb; |
990 | 990 | ||
991 | if (sk->sk_type != SOCK_STREAM) | 991 | if (sk->sk_type != SOCK_STREAM) |
992 | return -ENOPROTOOPT; | 992 | return -ENOPROTOOPT; |
993 | 993 | ||
994 | msg.msg_control = optval; | 994 | msg.msg_control = optval; |
995 | msg.msg_controllen = len; | 995 | msg.msg_controllen = len; |
996 | msg.msg_flags = flags; | 996 | msg.msg_flags = flags; |
997 | 997 | ||
998 | lock_sock(sk); | 998 | lock_sock(sk); |
999 | skb = np->pktoptions; | 999 | skb = np->pktoptions; |
1000 | if (skb) | 1000 | if (skb) |
1001 | atomic_inc(&skb->users); | 1001 | atomic_inc(&skb->users); |
1002 | release_sock(sk); | 1002 | release_sock(sk); |
1003 | 1003 | ||
1004 | if (skb) { | 1004 | if (skb) { |
1005 | int err = ip6_datagram_recv_ctl(sk, &msg, skb); | 1005 | int err = ip6_datagram_recv_ctl(sk, &msg, skb); |
1006 | kfree_skb(skb); | 1006 | kfree_skb(skb); |
1007 | if (err) | 1007 | if (err) |
1008 | return err; | 1008 | return err; |
1009 | } else { | 1009 | } else { |
1010 | if (np->rxopt.bits.rxinfo) { | 1010 | if (np->rxopt.bits.rxinfo) { |
1011 | struct in6_pktinfo src_info; | 1011 | struct in6_pktinfo src_info; |
1012 | src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : | 1012 | src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : |
1013 | np->sticky_pktinfo.ipi6_ifindex; | 1013 | np->sticky_pktinfo.ipi6_ifindex; |
1014 | src_info.ipi6_addr = np->mcast_oif ? sk->sk_v6_daddr : np->sticky_pktinfo.ipi6_addr; | 1014 | src_info.ipi6_addr = np->mcast_oif ? sk->sk_v6_daddr : np->sticky_pktinfo.ipi6_addr; |
1015 | put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info); | 1015 | put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info); |
1016 | } | 1016 | } |
1017 | if (np->rxopt.bits.rxhlim) { | 1017 | if (np->rxopt.bits.rxhlim) { |
1018 | int hlim = np->mcast_hops; | 1018 | int hlim = np->mcast_hops; |
1019 | put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim); | 1019 | put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim); |
1020 | } | 1020 | } |
1021 | if (np->rxopt.bits.rxtclass) { | 1021 | if (np->rxopt.bits.rxtclass) { |
1022 | int tclass = ntohl(np->rcv_flowinfo & IPV6_TCLASS_MASK) >> 20; | 1022 | int tclass = ntohl(np->rcv_flowinfo & IPV6_TCLASS_MASK) >> 20; |
1023 | put_cmsg(&msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass); | 1023 | put_cmsg(&msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass); |
1024 | } | 1024 | } |
1025 | if (np->rxopt.bits.rxoinfo) { | 1025 | if (np->rxopt.bits.rxoinfo) { |
1026 | struct in6_pktinfo src_info; | 1026 | struct in6_pktinfo src_info; |
1027 | src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : | 1027 | src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : |
1028 | np->sticky_pktinfo.ipi6_ifindex; | 1028 | np->sticky_pktinfo.ipi6_ifindex; |
1029 | src_info.ipi6_addr = np->mcast_oif ? sk->sk_v6_daddr : | 1029 | src_info.ipi6_addr = np->mcast_oif ? sk->sk_v6_daddr : |
1030 | np->sticky_pktinfo.ipi6_addr; | 1030 | np->sticky_pktinfo.ipi6_addr; |
1031 | put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info); | 1031 | put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info); |
1032 | } | 1032 | } |
1033 | if (np->rxopt.bits.rxohlim) { | 1033 | if (np->rxopt.bits.rxohlim) { |
1034 | int hlim = np->mcast_hops; | 1034 | int hlim = np->mcast_hops; |
1035 | put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim); | 1035 | put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim); |
1036 | } | 1036 | } |
1037 | if (np->rxopt.bits.rxflow) { | 1037 | if (np->rxopt.bits.rxflow) { |
1038 | int flowinfo = np->rcv_flowinfo; | 1038 | __be32 flowinfo = np->rcv_flowinfo; |
1039 | |||
1039 | put_cmsg(&msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo); | 1040 | put_cmsg(&msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo); |
1040 | } | 1041 | } |
1041 | } | 1042 | } |
1042 | len -= msg.msg_controllen; | 1043 | len -= msg.msg_controllen; |
1043 | return put_user(len, optlen); | 1044 | return put_user(len, optlen); |
1044 | } | 1045 | } |
1045 | case IPV6_MTU: | 1046 | case IPV6_MTU: |
1046 | { | 1047 | { |
1047 | struct dst_entry *dst; | 1048 | struct dst_entry *dst; |
1048 | 1049 | ||
1049 | val = 0; | 1050 | val = 0; |
1050 | rcu_read_lock(); | 1051 | rcu_read_lock(); |
1051 | dst = __sk_dst_get(sk); | 1052 | dst = __sk_dst_get(sk); |
1052 | if (dst) | 1053 | if (dst) |
1053 | val = dst_mtu(dst); | 1054 | val = dst_mtu(dst); |
1054 | rcu_read_unlock(); | 1055 | rcu_read_unlock(); |
1055 | if (!val) | 1056 | if (!val) |
1056 | return -ENOTCONN; | 1057 | return -ENOTCONN; |
1057 | break; | 1058 | break; |
1058 | } | 1059 | } |
1059 | 1060 | ||
1060 | case IPV6_V6ONLY: | 1061 | case IPV6_V6ONLY: |
1061 | val = np->ipv6only; | 1062 | val = np->ipv6only; |
1062 | break; | 1063 | break; |
1063 | 1064 | ||
1064 | case IPV6_RECVPKTINFO: | 1065 | case IPV6_RECVPKTINFO: |
1065 | val = np->rxopt.bits.rxinfo; | 1066 | val = np->rxopt.bits.rxinfo; |
1066 | break; | 1067 | break; |
1067 | 1068 | ||
1068 | case IPV6_2292PKTINFO: | 1069 | case IPV6_2292PKTINFO: |
1069 | val = np->rxopt.bits.rxoinfo; | 1070 | val = np->rxopt.bits.rxoinfo; |
1070 | break; | 1071 | break; |
1071 | 1072 | ||
1072 | case IPV6_RECVHOPLIMIT: | 1073 | case IPV6_RECVHOPLIMIT: |
1073 | val = np->rxopt.bits.rxhlim; | 1074 | val = np->rxopt.bits.rxhlim; |
1074 | break; | 1075 | break; |
1075 | 1076 | ||
1076 | case IPV6_2292HOPLIMIT: | 1077 | case IPV6_2292HOPLIMIT: |
1077 | val = np->rxopt.bits.rxohlim; | 1078 | val = np->rxopt.bits.rxohlim; |
1078 | break; | 1079 | break; |
1079 | 1080 | ||
1080 | case IPV6_RECVRTHDR: | 1081 | case IPV6_RECVRTHDR: |
1081 | val = np->rxopt.bits.srcrt; | 1082 | val = np->rxopt.bits.srcrt; |
1082 | break; | 1083 | break; |
1083 | 1084 | ||
1084 | case IPV6_2292RTHDR: | 1085 | case IPV6_2292RTHDR: |
1085 | val = np->rxopt.bits.osrcrt; | 1086 | val = np->rxopt.bits.osrcrt; |
1086 | break; | 1087 | break; |
1087 | 1088 | ||
1088 | case IPV6_HOPOPTS: | 1089 | case IPV6_HOPOPTS: |
1089 | case IPV6_RTHDRDSTOPTS: | 1090 | case IPV6_RTHDRDSTOPTS: |
1090 | case IPV6_RTHDR: | 1091 | case IPV6_RTHDR: |
1091 | case IPV6_DSTOPTS: | 1092 | case IPV6_DSTOPTS: |
1092 | { | 1093 | { |
1093 | 1094 | ||
1094 | lock_sock(sk); | 1095 | lock_sock(sk); |
1095 | len = ipv6_getsockopt_sticky(sk, np->opt, | 1096 | len = ipv6_getsockopt_sticky(sk, np->opt, |
1096 | optname, optval, len); | 1097 | optname, optval, len); |
1097 | release_sock(sk); | 1098 | release_sock(sk); |
1098 | /* check if ipv6_getsockopt_sticky() returns err code */ | 1099 | /* check if ipv6_getsockopt_sticky() returns err code */ |
1099 | if (len < 0) | 1100 | if (len < 0) |
1100 | return len; | 1101 | return len; |
1101 | return put_user(len, optlen); | 1102 | return put_user(len, optlen); |
1102 | } | 1103 | } |
1103 | 1104 | ||
1104 | case IPV6_RECVHOPOPTS: | 1105 | case IPV6_RECVHOPOPTS: |
1105 | val = np->rxopt.bits.hopopts; | 1106 | val = np->rxopt.bits.hopopts; |
1106 | break; | 1107 | break; |
1107 | 1108 | ||
1108 | case IPV6_2292HOPOPTS: | 1109 | case IPV6_2292HOPOPTS: |
1109 | val = np->rxopt.bits.ohopopts; | 1110 | val = np->rxopt.bits.ohopopts; |
1110 | break; | 1111 | break; |
1111 | 1112 | ||
1112 | case IPV6_RECVDSTOPTS: | 1113 | case IPV6_RECVDSTOPTS: |
1113 | val = np->rxopt.bits.dstopts; | 1114 | val = np->rxopt.bits.dstopts; |
1114 | break; | 1115 | break; |
1115 | 1116 | ||
1116 | case IPV6_2292DSTOPTS: | 1117 | case IPV6_2292DSTOPTS: |
1117 | val = np->rxopt.bits.odstopts; | 1118 | val = np->rxopt.bits.odstopts; |
1118 | break; | 1119 | break; |
1119 | 1120 | ||
1120 | case IPV6_TCLASS: | 1121 | case IPV6_TCLASS: |
1121 | val = np->tclass; | 1122 | val = np->tclass; |
1122 | break; | 1123 | break; |
1123 | 1124 | ||
1124 | case IPV6_RECVTCLASS: | 1125 | case IPV6_RECVTCLASS: |
1125 | val = np->rxopt.bits.rxtclass; | 1126 | val = np->rxopt.bits.rxtclass; |
1126 | break; | 1127 | break; |
1127 | 1128 | ||
1128 | case IPV6_FLOWINFO: | 1129 | case IPV6_FLOWINFO: |
1129 | val = np->rxopt.bits.rxflow; | 1130 | val = np->rxopt.bits.rxflow; |
1130 | break; | 1131 | break; |
1131 | 1132 | ||
1132 | case IPV6_RECVPATHMTU: | 1133 | case IPV6_RECVPATHMTU: |
1133 | val = np->rxopt.bits.rxpmtu; | 1134 | val = np->rxopt.bits.rxpmtu; |
1134 | break; | 1135 | break; |
1135 | 1136 | ||
1136 | case IPV6_PATHMTU: | 1137 | case IPV6_PATHMTU: |
1137 | { | 1138 | { |
1138 | struct dst_entry *dst; | 1139 | struct dst_entry *dst; |
1139 | struct ip6_mtuinfo mtuinfo; | 1140 | struct ip6_mtuinfo mtuinfo; |
1140 | 1141 | ||
1141 | if (len < sizeof(mtuinfo)) | 1142 | if (len < sizeof(mtuinfo)) |
1142 | return -EINVAL; | 1143 | return -EINVAL; |
1143 | 1144 | ||
1144 | len = sizeof(mtuinfo); | 1145 | len = sizeof(mtuinfo); |
1145 | memset(&mtuinfo, 0, sizeof(mtuinfo)); | 1146 | memset(&mtuinfo, 0, sizeof(mtuinfo)); |
1146 | 1147 | ||
1147 | rcu_read_lock(); | 1148 | rcu_read_lock(); |
1148 | dst = __sk_dst_get(sk); | 1149 | dst = __sk_dst_get(sk); |
1149 | if (dst) | 1150 | if (dst) |
1150 | mtuinfo.ip6m_mtu = dst_mtu(dst); | 1151 | mtuinfo.ip6m_mtu = dst_mtu(dst); |
1151 | rcu_read_unlock(); | 1152 | rcu_read_unlock(); |
1152 | if (!mtuinfo.ip6m_mtu) | 1153 | if (!mtuinfo.ip6m_mtu) |
1153 | return -ENOTCONN; | 1154 | return -ENOTCONN; |
1154 | 1155 | ||
1155 | if (put_user(len, optlen)) | 1156 | if (put_user(len, optlen)) |
1156 | return -EFAULT; | 1157 | return -EFAULT; |
1157 | if (copy_to_user(optval, &mtuinfo, len)) | 1158 | if (copy_to_user(optval, &mtuinfo, len)) |
1158 | return -EFAULT; | 1159 | return -EFAULT; |
1159 | 1160 | ||
1160 | return 0; | 1161 | return 0; |
1161 | break; | 1162 | break; |
1162 | } | 1163 | } |
1163 | 1164 | ||
1164 | case IPV6_TRANSPARENT: | 1165 | case IPV6_TRANSPARENT: |
1165 | val = inet_sk(sk)->transparent; | 1166 | val = inet_sk(sk)->transparent; |
1166 | break; | 1167 | break; |
1167 | 1168 | ||
1168 | case IPV6_RECVORIGDSTADDR: | 1169 | case IPV6_RECVORIGDSTADDR: |
1169 | val = np->rxopt.bits.rxorigdstaddr; | 1170 | val = np->rxopt.bits.rxorigdstaddr; |
1170 | break; | 1171 | break; |
1171 | 1172 | ||
1172 | case IPV6_UNICAST_HOPS: | 1173 | case IPV6_UNICAST_HOPS: |
1173 | case IPV6_MULTICAST_HOPS: | 1174 | case IPV6_MULTICAST_HOPS: |
1174 | { | 1175 | { |
1175 | struct dst_entry *dst; | 1176 | struct dst_entry *dst; |
1176 | 1177 | ||
1177 | if (optname == IPV6_UNICAST_HOPS) | 1178 | if (optname == IPV6_UNICAST_HOPS) |
1178 | val = np->hop_limit; | 1179 | val = np->hop_limit; |
1179 | else | 1180 | else |
1180 | val = np->mcast_hops; | 1181 | val = np->mcast_hops; |
1181 | 1182 | ||
1182 | if (val < 0) { | 1183 | if (val < 0) { |
1183 | rcu_read_lock(); | 1184 | rcu_read_lock(); |
1184 | dst = __sk_dst_get(sk); | 1185 | dst = __sk_dst_get(sk); |
1185 | if (dst) | 1186 | if (dst) |
1186 | val = ip6_dst_hoplimit(dst); | 1187 | val = ip6_dst_hoplimit(dst); |
1187 | rcu_read_unlock(); | 1188 | rcu_read_unlock(); |
1188 | } | 1189 | } |
1189 | 1190 | ||
1190 | if (val < 0) | 1191 | if (val < 0) |
1191 | val = sock_net(sk)->ipv6.devconf_all->hop_limit; | 1192 | val = sock_net(sk)->ipv6.devconf_all->hop_limit; |
1192 | break; | 1193 | break; |
1193 | } | 1194 | } |
1194 | 1195 | ||
1195 | case IPV6_MULTICAST_LOOP: | 1196 | case IPV6_MULTICAST_LOOP: |
1196 | val = np->mc_loop; | 1197 | val = np->mc_loop; |
1197 | break; | 1198 | break; |
1198 | 1199 | ||
1199 | case IPV6_MULTICAST_IF: | 1200 | case IPV6_MULTICAST_IF: |
1200 | val = np->mcast_oif; | 1201 | val = np->mcast_oif; |
1201 | break; | 1202 | break; |
1202 | 1203 | ||
1203 | case IPV6_UNICAST_IF: | 1204 | case IPV6_UNICAST_IF: |
1204 | val = (__force int)htonl((__u32) np->ucast_oif); | 1205 | val = (__force int)htonl((__u32) np->ucast_oif); |
1205 | break; | 1206 | break; |
1206 | 1207 | ||
1207 | case IPV6_MTU_DISCOVER: | 1208 | case IPV6_MTU_DISCOVER: |
1208 | val = np->pmtudisc; | 1209 | val = np->pmtudisc; |
1209 | break; | 1210 | break; |
1210 | 1211 | ||
1211 | case IPV6_RECVERR: | 1212 | case IPV6_RECVERR: |
1212 | val = np->recverr; | 1213 | val = np->recverr; |
1213 | break; | 1214 | break; |
1214 | 1215 | ||
1215 | case IPV6_FLOWINFO_SEND: | 1216 | case IPV6_FLOWINFO_SEND: |
1216 | val = np->sndflow; | 1217 | val = np->sndflow; |
1217 | break; | 1218 | break; |
1218 | 1219 | ||
1219 | case IPV6_FLOWLABEL_MGR: | 1220 | case IPV6_FLOWLABEL_MGR: |
1220 | { | 1221 | { |
1221 | struct in6_flowlabel_req freq; | 1222 | struct in6_flowlabel_req freq; |
1222 | 1223 | ||
1223 | if (len < sizeof(freq)) | 1224 | if (len < sizeof(freq)) |
1224 | return -EINVAL; | 1225 | return -EINVAL; |
1225 | 1226 | ||
1226 | if (copy_from_user(&freq, optval, sizeof(freq))) | 1227 | if (copy_from_user(&freq, optval, sizeof(freq))) |
1227 | return -EFAULT; | 1228 | return -EFAULT; |
1228 | 1229 | ||
1229 | if (freq.flr_action != IPV6_FL_A_GET) | 1230 | if (freq.flr_action != IPV6_FL_A_GET) |
1230 | return -EINVAL; | 1231 | return -EINVAL; |
1231 | 1232 | ||
1232 | len = sizeof(freq); | 1233 | len = sizeof(freq); |
1233 | memset(&freq, 0, sizeof(freq)); | 1234 | memset(&freq, 0, sizeof(freq)); |
1234 | 1235 | ||
1235 | val = ipv6_flowlabel_opt_get(sk, &freq); | 1236 | val = ipv6_flowlabel_opt_get(sk, &freq); |
1236 | if (val < 0) | 1237 | if (val < 0) |
1237 | return val; | 1238 | return val; |
1238 | 1239 | ||
1239 | if (put_user(len, optlen)) | 1240 | if (put_user(len, optlen)) |
1240 | return -EFAULT; | 1241 | return -EFAULT; |
1241 | if (copy_to_user(optval, &freq, len)) | 1242 | if (copy_to_user(optval, &freq, len)) |
1242 | return -EFAULT; | 1243 | return -EFAULT; |
1243 | 1244 | ||
1244 | return 0; | 1245 | return 0; |
1245 | } | 1246 | } |
1246 | 1247 | ||
1247 | case IPV6_ADDR_PREFERENCES: | 1248 | case IPV6_ADDR_PREFERENCES: |
1248 | val = 0; | 1249 | val = 0; |
1249 | 1250 | ||
1250 | if (np->srcprefs & IPV6_PREFER_SRC_TMP) | 1251 | if (np->srcprefs & IPV6_PREFER_SRC_TMP) |
1251 | val |= IPV6_PREFER_SRC_TMP; | 1252 | val |= IPV6_PREFER_SRC_TMP; |
1252 | else if (np->srcprefs & IPV6_PREFER_SRC_PUBLIC) | 1253 | else if (np->srcprefs & IPV6_PREFER_SRC_PUBLIC) |
1253 | val |= IPV6_PREFER_SRC_PUBLIC; | 1254 | val |= IPV6_PREFER_SRC_PUBLIC; |
1254 | else { | 1255 | else { |
1255 | /* XXX: should we return system default? */ | 1256 | /* XXX: should we return system default? */ |
1256 | val |= IPV6_PREFER_SRC_PUBTMP_DEFAULT; | 1257 | val |= IPV6_PREFER_SRC_PUBTMP_DEFAULT; |
1257 | } | 1258 | } |
1258 | 1259 | ||
1259 | if (np->srcprefs & IPV6_PREFER_SRC_COA) | 1260 | if (np->srcprefs & IPV6_PREFER_SRC_COA) |
1260 | val |= IPV6_PREFER_SRC_COA; | 1261 | val |= IPV6_PREFER_SRC_COA; |
1261 | else | 1262 | else |
1262 | val |= IPV6_PREFER_SRC_HOME; | 1263 | val |= IPV6_PREFER_SRC_HOME; |
1263 | break; | 1264 | break; |
1264 | 1265 | ||
1265 | case IPV6_MINHOPCOUNT: | 1266 | case IPV6_MINHOPCOUNT: |
1266 | val = np->min_hopcount; | 1267 | val = np->min_hopcount; |
1267 | break; | 1268 | break; |
1268 | 1269 | ||
1269 | case IPV6_DONTFRAG: | 1270 | case IPV6_DONTFRAG: |
1270 | val = np->dontfrag; | 1271 | val = np->dontfrag; |
1271 | break; | 1272 | break; |
1272 | 1273 | ||
1273 | default: | 1274 | default: |
1274 | return -ENOPROTOOPT; | 1275 | return -ENOPROTOOPT; |
1275 | } | 1276 | } |
1276 | len = min_t(unsigned int, sizeof(int), len); | 1277 | len = min_t(unsigned int, sizeof(int), len); |
1277 | if(put_user(len, optlen)) | 1278 | if(put_user(len, optlen)) |
1278 | return -EFAULT; | 1279 | return -EFAULT; |
1279 | if(copy_to_user(optval,&val,len)) | 1280 | if(copy_to_user(optval,&val,len)) |
1280 | return -EFAULT; | 1281 | return -EFAULT; |
1281 | return 0; | 1282 | return 0; |
1282 | } | 1283 | } |
1283 | 1284 | ||
1284 | int ipv6_getsockopt(struct sock *sk, int level, int optname, | 1285 | int ipv6_getsockopt(struct sock *sk, int level, int optname, |
1285 | char __user *optval, int __user *optlen) | 1286 | char __user *optval, int __user *optlen) |
1286 | { | 1287 | { |
1287 | int err; | 1288 | int err; |
1288 | 1289 | ||
1289 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) | 1290 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) |
1290 | return udp_prot.getsockopt(sk, level, optname, optval, optlen); | 1291 | return udp_prot.getsockopt(sk, level, optname, optval, optlen); |
1291 | 1292 | ||
1292 | if(level != SOL_IPV6) | 1293 | if(level != SOL_IPV6) |
1293 | return -ENOPROTOOPT; | 1294 | return -ENOPROTOOPT; |
1294 | 1295 | ||
1295 | err = do_ipv6_getsockopt(sk, level, optname, optval, optlen, 0); | 1296 | err = do_ipv6_getsockopt(sk, level, optname, optval, optlen, 0); |
1296 | #ifdef CONFIG_NETFILTER | 1297 | #ifdef CONFIG_NETFILTER |
1297 | /* we need to exclude all possible ENOPROTOOPTs except default case */ | 1298 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
1298 | if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) { | 1299 | if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) { |
1299 | int len; | 1300 | int len; |
1300 | 1301 | ||
1301 | if (get_user(len, optlen)) | 1302 | if (get_user(len, optlen)) |
1302 | return -EFAULT; | 1303 | return -EFAULT; |
1303 | 1304 | ||
1304 | lock_sock(sk); | 1305 | lock_sock(sk); |
1305 | err = nf_getsockopt(sk, PF_INET6, optname, optval, | 1306 | err = nf_getsockopt(sk, PF_INET6, optname, optval, |
1306 | &len); | 1307 | &len); |
1307 | release_sock(sk); | 1308 | release_sock(sk); |
1308 | if (err >= 0) | 1309 | if (err >= 0) |
1309 | err = put_user(len, optlen); | 1310 | err = put_user(len, optlen); |
1310 | } | 1311 | } |
1311 | #endif | 1312 | #endif |
1312 | return err; | 1313 | return err; |
1313 | } | 1314 | } |
1314 | 1315 | ||
1315 | EXPORT_SYMBOL(ipv6_getsockopt); | 1316 | EXPORT_SYMBOL(ipv6_getsockopt); |
1316 | 1317 | ||
1317 | #ifdef CONFIG_COMPAT | 1318 | #ifdef CONFIG_COMPAT |
1318 | int compat_ipv6_getsockopt(struct sock *sk, int level, int optname, | 1319 | int compat_ipv6_getsockopt(struct sock *sk, int level, int optname, |
1319 | char __user *optval, int __user *optlen) | 1320 | char __user *optval, int __user *optlen) |
1320 | { | 1321 | { |
1321 | int err; | 1322 | int err; |
1322 | 1323 | ||
1323 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) { | 1324 | if (level == SOL_IP && sk->sk_type != SOCK_RAW) { |
1324 | if (udp_prot.compat_getsockopt != NULL) | 1325 | if (udp_prot.compat_getsockopt != NULL) |
1325 | return udp_prot.compat_getsockopt(sk, level, optname, | 1326 | return udp_prot.compat_getsockopt(sk, level, optname, |
1326 | optval, optlen); | 1327 | optval, optlen); |
1327 | return udp_prot.getsockopt(sk, level, optname, optval, optlen); | 1328 | return udp_prot.getsockopt(sk, level, optname, optval, optlen); |
1328 | } | 1329 | } |
1329 | 1330 | ||
1330 | if (level != SOL_IPV6) | 1331 | if (level != SOL_IPV6) |
1331 | return -ENOPROTOOPT; | 1332 | return -ENOPROTOOPT; |
1332 | 1333 | ||
1333 | if (optname == MCAST_MSFILTER) | 1334 | if (optname == MCAST_MSFILTER) |
1334 | return compat_mc_getsockopt(sk, level, optname, optval, optlen, | 1335 | return compat_mc_getsockopt(sk, level, optname, optval, optlen, |
1335 | ipv6_getsockopt); | 1336 | ipv6_getsockopt); |
1336 | 1337 | ||
1337 | err = do_ipv6_getsockopt(sk, level, optname, optval, optlen, | 1338 | err = do_ipv6_getsockopt(sk, level, optname, optval, optlen, |
1338 | MSG_CMSG_COMPAT); | 1339 | MSG_CMSG_COMPAT); |
1339 | #ifdef CONFIG_NETFILTER | 1340 | #ifdef CONFIG_NETFILTER |
1340 | /* we need to exclude all possible ENOPROTOOPTs except default case */ | 1341 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
1341 | if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) { | 1342 | if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) { |
1342 | int len; | 1343 | int len; |
1343 | 1344 | ||
1344 | if (get_user(len, optlen)) | 1345 | if (get_user(len, optlen)) |
1345 | return -EFAULT; | 1346 | return -EFAULT; |
1346 | 1347 | ||
1347 | lock_sock(sk); | 1348 | lock_sock(sk); |
1348 | err = compat_nf_getsockopt(sk, PF_INET6, | 1349 | err = compat_nf_getsockopt(sk, PF_INET6, |
1349 | optname, optval, &len); | 1350 | optname, optval, &len); |
1350 | release_sock(sk); | 1351 | release_sock(sk); |
1351 | if (err >= 0) | 1352 | if (err >= 0) |
1352 | err = put_user(len, optlen); | 1353 | err = put_user(len, optlen); |
1353 | } | 1354 | } |
1354 | #endif | 1355 | #endif |
1355 | return err; | 1356 | return err; |
1356 | } | 1357 | } |
1357 | 1358 | ||
1358 | EXPORT_SYMBOL(compat_ipv6_getsockopt); | 1359 | EXPORT_SYMBOL(compat_ipv6_getsockopt); |
1359 | #endif | 1360 | #endif |
1360 | 1361 | ||
1361 | 1362 |