ipv6_sockglue.c 28 KB

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