ip_options.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * The options processing module for ip.c
  7. *
  8. * Authors: A.N.Kuznetsov
  9. *
  10. */
  11. #define pr_fmt(fmt) "IPv4: " fmt
  12. #include <linux/capability.h>
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/types.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/unaligned.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/ip.h>
  20. #include <linux/icmp.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/rtnetlink.h>
  23. #include <net/sock.h>
  24. #include <net/ip.h>
  25. #include <net/icmp.h>
  26. #include <net/route.h>
  27. #include <net/cipso_ipv4.h>
  28. #include <net/ip_fib.h>
  29. /*
  30. * Write options to IP header, record destination address to
  31. * source route option, address of outgoing interface
  32. * (we should already know it, so that this function is allowed be
  33. * called only after routing decision) and timestamp,
  34. * if we originate this datagram.
  35. *
  36. * daddr is real destination address, next hop is recorded in IP header.
  37. * saddr is address of outgoing interface.
  38. */
  39. void ip_options_build(struct sk_buff *skb, struct ip_options *opt,
  40. __be32 daddr, struct rtable *rt, int is_frag)
  41. {
  42. unsigned char *iph = skb_network_header(skb);
  43. memcpy(&(IPCB(skb)->opt), opt, sizeof(struct ip_options));
  44. memcpy(iph+sizeof(struct iphdr), opt->__data, opt->optlen);
  45. opt = &(IPCB(skb)->opt);
  46. if (opt->srr)
  47. memcpy(iph+opt->srr+iph[opt->srr+1]-4, &daddr, 4);
  48. if (!is_frag) {
  49. if (opt->rr_needaddr)
  50. ip_rt_get_source(iph+opt->rr+iph[opt->rr+2]-5, skb, rt);
  51. if (opt->ts_needaddr)
  52. ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, skb, rt);
  53. if (opt->ts_needtime) {
  54. struct timespec tv;
  55. __be32 midtime;
  56. getnstimeofday(&tv);
  57. midtime = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC);
  58. memcpy(iph+opt->ts+iph[opt->ts+2]-5, &midtime, 4);
  59. }
  60. return;
  61. }
  62. if (opt->rr) {
  63. memset(iph+opt->rr, IPOPT_NOP, iph[opt->rr+1]);
  64. opt->rr = 0;
  65. opt->rr_needaddr = 0;
  66. }
  67. if (opt->ts) {
  68. memset(iph+opt->ts, IPOPT_NOP, iph[opt->ts+1]);
  69. opt->ts = 0;
  70. opt->ts_needaddr = opt->ts_needtime = 0;
  71. }
  72. }
  73. /*
  74. * Provided (sopt, skb) points to received options,
  75. * build in dopt compiled option set appropriate for answering.
  76. * i.e. invert SRR option, copy anothers,
  77. * and grab room in RR/TS options.
  78. *
  79. * NOTE: dopt cannot point to skb.
  80. */
  81. int __ip_options_echo(struct ip_options *dopt, struct sk_buff *skb,
  82. const struct ip_options *sopt)
  83. {
  84. unsigned char *sptr, *dptr;
  85. int soffset, doffset;
  86. int optlen;
  87. memset(dopt, 0, sizeof(struct ip_options));
  88. if (sopt->optlen == 0)
  89. return 0;
  90. sptr = skb_network_header(skb);
  91. dptr = dopt->__data;
  92. if (sopt->rr) {
  93. optlen = sptr[sopt->rr+1];
  94. soffset = sptr[sopt->rr+2];
  95. dopt->rr = dopt->optlen + sizeof(struct iphdr);
  96. memcpy(dptr, sptr+sopt->rr, optlen);
  97. if (sopt->rr_needaddr && soffset <= optlen) {
  98. if (soffset + 3 > optlen)
  99. return -EINVAL;
  100. dptr[2] = soffset + 4;
  101. dopt->rr_needaddr = 1;
  102. }
  103. dptr += optlen;
  104. dopt->optlen += optlen;
  105. }
  106. if (sopt->ts) {
  107. optlen = sptr[sopt->ts+1];
  108. soffset = sptr[sopt->ts+2];
  109. dopt->ts = dopt->optlen + sizeof(struct iphdr);
  110. memcpy(dptr, sptr+sopt->ts, optlen);
  111. if (soffset <= optlen) {
  112. if (sopt->ts_needaddr) {
  113. if (soffset + 3 > optlen)
  114. return -EINVAL;
  115. dopt->ts_needaddr = 1;
  116. soffset += 4;
  117. }
  118. if (sopt->ts_needtime) {
  119. if (soffset + 3 > optlen)
  120. return -EINVAL;
  121. if ((dptr[3]&0xF) != IPOPT_TS_PRESPEC) {
  122. dopt->ts_needtime = 1;
  123. soffset += 4;
  124. } else {
  125. dopt->ts_needtime = 0;
  126. if (soffset + 7 <= optlen) {
  127. __be32 addr;
  128. memcpy(&addr, dptr+soffset-1, 4);
  129. if (inet_addr_type(dev_net(skb_dst(skb)->dev), addr) != RTN_UNICAST) {
  130. dopt->ts_needtime = 1;
  131. soffset += 8;
  132. }
  133. }
  134. }
  135. }
  136. dptr[2] = soffset;
  137. }
  138. dptr += optlen;
  139. dopt->optlen += optlen;
  140. }
  141. if (sopt->srr) {
  142. unsigned char *start = sptr+sopt->srr;
  143. __be32 faddr;
  144. optlen = start[1];
  145. soffset = start[2];
  146. doffset = 0;
  147. if (soffset > optlen)
  148. soffset = optlen + 1;
  149. soffset -= 4;
  150. if (soffset > 3) {
  151. memcpy(&faddr, &start[soffset-1], 4);
  152. for (soffset -= 4, doffset = 4; soffset > 3; soffset -= 4, doffset += 4)
  153. memcpy(&dptr[doffset-1], &start[soffset-1], 4);
  154. /*
  155. * RFC1812 requires to fix illegal source routes.
  156. */
  157. if (memcmp(&ip_hdr(skb)->saddr,
  158. &start[soffset + 3], 4) == 0)
  159. doffset -= 4;
  160. }
  161. if (doffset > 3) {
  162. __be32 daddr = fib_compute_spec_dst(skb);
  163. memcpy(&start[doffset-1], &daddr, 4);
  164. dopt->faddr = faddr;
  165. dptr[0] = start[0];
  166. dptr[1] = doffset+3;
  167. dptr[2] = 4;
  168. dptr += doffset+3;
  169. dopt->srr = dopt->optlen + sizeof(struct iphdr);
  170. dopt->optlen += doffset+3;
  171. dopt->is_strictroute = sopt->is_strictroute;
  172. }
  173. }
  174. if (sopt->cipso) {
  175. optlen = sptr[sopt->cipso+1];
  176. dopt->cipso = dopt->optlen+sizeof(struct iphdr);
  177. memcpy(dptr, sptr+sopt->cipso, optlen);
  178. dptr += optlen;
  179. dopt->optlen += optlen;
  180. }
  181. while (dopt->optlen & 3) {
  182. *dptr++ = IPOPT_END;
  183. dopt->optlen++;
  184. }
  185. return 0;
  186. }
  187. /*
  188. * Options "fragmenting", just fill options not
  189. * allowed in fragments with NOOPs.
  190. * Simple and stupid 8), but the most efficient way.
  191. */
  192. void ip_options_fragment(struct sk_buff *skb)
  193. {
  194. unsigned char *optptr = skb_network_header(skb) + sizeof(struct iphdr);
  195. struct ip_options *opt = &(IPCB(skb)->opt);
  196. int l = opt->optlen;
  197. int optlen;
  198. while (l > 0) {
  199. switch (*optptr) {
  200. case IPOPT_END:
  201. return;
  202. case IPOPT_NOOP:
  203. l--;
  204. optptr++;
  205. continue;
  206. }
  207. optlen = optptr[1];
  208. if (optlen < 2 || optlen > l)
  209. return;
  210. if (!IPOPT_COPIED(*optptr))
  211. memset(optptr, IPOPT_NOOP, optlen);
  212. l -= optlen;
  213. optptr += optlen;
  214. }
  215. opt->ts = 0;
  216. opt->rr = 0;
  217. opt->rr_needaddr = 0;
  218. opt->ts_needaddr = 0;
  219. opt->ts_needtime = 0;
  220. }
  221. /* helper used by ip_options_compile() to call fib_compute_spec_dst()
  222. * at most one time.
  223. */
  224. static void spec_dst_fill(__be32 *spec_dst, struct sk_buff *skb)
  225. {
  226. if (*spec_dst == htonl(INADDR_ANY))
  227. *spec_dst = fib_compute_spec_dst(skb);
  228. }
  229. /*
  230. * Verify options and fill pointers in struct options.
  231. * Caller should clear *opt, and set opt->data.
  232. * If opt == NULL, then skb->data should point to IP header.
  233. */
  234. int __ip_options_compile(struct net *net,
  235. struct ip_options *opt, struct sk_buff *skb,
  236. __be32 *info)
  237. {
  238. __be32 spec_dst = htonl(INADDR_ANY);
  239. unsigned char *pp_ptr = NULL;
  240. struct rtable *rt = NULL;
  241. unsigned char *optptr;
  242. unsigned char *iph;
  243. int optlen, l;
  244. if (skb) {
  245. rt = skb_rtable(skb);
  246. optptr = (unsigned char *)&(ip_hdr(skb)[1]);
  247. } else
  248. optptr = opt->__data;
  249. iph = optptr - sizeof(struct iphdr);
  250. for (l = opt->optlen; l > 0; ) {
  251. switch (*optptr) {
  252. case IPOPT_END:
  253. for (optptr++, l--; l > 0; optptr++, l--) {
  254. if (*optptr != IPOPT_END) {
  255. *optptr = IPOPT_END;
  256. opt->is_changed = 1;
  257. }
  258. }
  259. goto eol;
  260. case IPOPT_NOOP:
  261. l--;
  262. optptr++;
  263. continue;
  264. }
  265. if (unlikely(l < 2)) {
  266. pp_ptr = optptr;
  267. goto error;
  268. }
  269. optlen = optptr[1];
  270. if (optlen < 2 || optlen > l) {
  271. pp_ptr = optptr;
  272. goto error;
  273. }
  274. switch (*optptr) {
  275. case IPOPT_SSRR:
  276. case IPOPT_LSRR:
  277. if (optlen < 3) {
  278. pp_ptr = optptr + 1;
  279. goto error;
  280. }
  281. if (optptr[2] < 4) {
  282. pp_ptr = optptr + 2;
  283. goto error;
  284. }
  285. /* NB: cf RFC-1812 5.2.4.1 */
  286. if (opt->srr) {
  287. pp_ptr = optptr;
  288. goto error;
  289. }
  290. if (!skb) {
  291. if (optptr[2] != 4 || optlen < 7 || ((optlen-3) & 3)) {
  292. pp_ptr = optptr + 1;
  293. goto error;
  294. }
  295. memcpy(&opt->faddr, &optptr[3], 4);
  296. if (optlen > 7)
  297. memmove(&optptr[3], &optptr[7], optlen-7);
  298. }
  299. opt->is_strictroute = (optptr[0] == IPOPT_SSRR);
  300. opt->srr = optptr - iph;
  301. break;
  302. case IPOPT_RR:
  303. if (opt->rr) {
  304. pp_ptr = optptr;
  305. goto error;
  306. }
  307. if (optlen < 3) {
  308. pp_ptr = optptr + 1;
  309. goto error;
  310. }
  311. if (optptr[2] < 4) {
  312. pp_ptr = optptr + 2;
  313. goto error;
  314. }
  315. if (optptr[2] <= optlen) {
  316. if (optptr[2]+3 > optlen) {
  317. pp_ptr = optptr + 2;
  318. goto error;
  319. }
  320. if (rt) {
  321. spec_dst_fill(&spec_dst, skb);
  322. memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
  323. opt->is_changed = 1;
  324. }
  325. optptr[2] += 4;
  326. opt->rr_needaddr = 1;
  327. }
  328. opt->rr = optptr - iph;
  329. break;
  330. case IPOPT_TIMESTAMP:
  331. if (opt->ts) {
  332. pp_ptr = optptr;
  333. goto error;
  334. }
  335. if (optlen < 4) {
  336. pp_ptr = optptr + 1;
  337. goto error;
  338. }
  339. if (optptr[2] < 5) {
  340. pp_ptr = optptr + 2;
  341. goto error;
  342. }
  343. if (optptr[2] <= optlen) {
  344. unsigned char *timeptr = NULL;
  345. if (optptr[2]+3 > optlen) {
  346. pp_ptr = optptr + 2;
  347. goto error;
  348. }
  349. switch (optptr[3]&0xF) {
  350. case IPOPT_TS_TSONLY:
  351. if (skb)
  352. timeptr = &optptr[optptr[2]-1];
  353. opt->ts_needtime = 1;
  354. optptr[2] += 4;
  355. break;
  356. case IPOPT_TS_TSANDADDR:
  357. if (optptr[2]+7 > optlen) {
  358. pp_ptr = optptr + 2;
  359. goto error;
  360. }
  361. if (rt) {
  362. spec_dst_fill(&spec_dst, skb);
  363. memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
  364. timeptr = &optptr[optptr[2]+3];
  365. }
  366. opt->ts_needaddr = 1;
  367. opt->ts_needtime = 1;
  368. optptr[2] += 8;
  369. break;
  370. case IPOPT_TS_PRESPEC:
  371. if (optptr[2]+7 > optlen) {
  372. pp_ptr = optptr + 2;
  373. goto error;
  374. }
  375. {
  376. __be32 addr;
  377. memcpy(&addr, &optptr[optptr[2]-1], 4);
  378. if (inet_addr_type(net, addr) == RTN_UNICAST)
  379. break;
  380. if (skb)
  381. timeptr = &optptr[optptr[2]+3];
  382. }
  383. opt->ts_needtime = 1;
  384. optptr[2] += 8;
  385. break;
  386. default:
  387. if (!skb && !ns_capable(net->user_ns, CAP_NET_RAW)) {
  388. pp_ptr = optptr + 3;
  389. goto error;
  390. }
  391. break;
  392. }
  393. if (timeptr) {
  394. struct timespec tv;
  395. u32 midtime;
  396. getnstimeofday(&tv);
  397. midtime = (tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC;
  398. put_unaligned_be32(midtime, timeptr);
  399. opt->is_changed = 1;
  400. }
  401. } else if ((optptr[3]&0xF) != IPOPT_TS_PRESPEC) {
  402. unsigned int overflow = optptr[3]>>4;
  403. if (overflow == 15) {
  404. pp_ptr = optptr + 3;
  405. goto error;
  406. }
  407. if (skb) {
  408. optptr[3] = (optptr[3]&0xF)|((overflow+1)<<4);
  409. opt->is_changed = 1;
  410. }
  411. }
  412. opt->ts = optptr - iph;
  413. break;
  414. case IPOPT_RA:
  415. if (optlen < 4) {
  416. pp_ptr = optptr + 1;
  417. goto error;
  418. }
  419. if (optptr[2] == 0 && optptr[3] == 0)
  420. opt->router_alert = optptr - iph;
  421. break;
  422. case IPOPT_CIPSO:
  423. if ((!skb && !ns_capable(net->user_ns, CAP_NET_RAW)) || opt->cipso) {
  424. pp_ptr = optptr;
  425. goto error;
  426. }
  427. opt->cipso = optptr - iph;
  428. if (cipso_v4_validate(skb, &optptr)) {
  429. pp_ptr = optptr;
  430. goto error;
  431. }
  432. break;
  433. case IPOPT_SEC:
  434. case IPOPT_SID:
  435. default:
  436. if (!skb && !ns_capable(net->user_ns, CAP_NET_RAW)) {
  437. pp_ptr = optptr;
  438. goto error;
  439. }
  440. break;
  441. }
  442. l -= optlen;
  443. optptr += optlen;
  444. }
  445. eol:
  446. if (!pp_ptr)
  447. return 0;
  448. error:
  449. if (info)
  450. *info = htonl((pp_ptr-iph)<<24);
  451. return -EINVAL;
  452. }
  453. int ip_options_compile(struct net *net,
  454. struct ip_options *opt, struct sk_buff *skb)
  455. {
  456. int ret;
  457. __be32 info;
  458. ret = __ip_options_compile(net, opt, skb, &info);
  459. if (ret != 0 && skb)
  460. icmp_send(skb, ICMP_PARAMETERPROB, 0, info);
  461. return ret;
  462. }
  463. EXPORT_SYMBOL(ip_options_compile);
  464. /*
  465. * Undo all the changes done by ip_options_compile().
  466. */
  467. void ip_options_undo(struct ip_options *opt)
  468. {
  469. if (opt->srr) {
  470. unsigned char *optptr = opt->__data+opt->srr-sizeof(struct iphdr);
  471. memmove(optptr+7, optptr+3, optptr[1]-7);
  472. memcpy(optptr+3, &opt->faddr, 4);
  473. }
  474. if (opt->rr_needaddr) {
  475. unsigned char *optptr = opt->__data+opt->rr-sizeof(struct iphdr);
  476. optptr[2] -= 4;
  477. memset(&optptr[optptr[2]-1], 0, 4);
  478. }
  479. if (opt->ts) {
  480. unsigned char *optptr = opt->__data+opt->ts-sizeof(struct iphdr);
  481. if (opt->ts_needtime) {
  482. optptr[2] -= 4;
  483. memset(&optptr[optptr[2]-1], 0, 4);
  484. if ((optptr[3]&0xF) == IPOPT_TS_PRESPEC)
  485. optptr[2] -= 4;
  486. }
  487. if (opt->ts_needaddr) {
  488. optptr[2] -= 4;
  489. memset(&optptr[optptr[2]-1], 0, 4);
  490. }
  491. }
  492. }
  493. static struct ip_options_rcu *ip_options_get_alloc(const int optlen)
  494. {
  495. return kzalloc(sizeof(struct ip_options_rcu) + ((optlen + 3) & ~3),
  496. GFP_KERNEL);
  497. }
  498. static int ip_options_get_finish(struct net *net, struct ip_options_rcu **optp,
  499. struct ip_options_rcu *opt, int optlen)
  500. {
  501. while (optlen & 3)
  502. opt->opt.__data[optlen++] = IPOPT_END;
  503. opt->opt.optlen = optlen;
  504. if (optlen && ip_options_compile(net, &opt->opt, NULL)) {
  505. kfree(opt);
  506. return -EINVAL;
  507. }
  508. kfree(*optp);
  509. *optp = opt;
  510. return 0;
  511. }
  512. int ip_options_get_from_user(struct net *net, struct ip_options_rcu **optp,
  513. unsigned char __user *data, int optlen)
  514. {
  515. struct ip_options_rcu *opt = ip_options_get_alloc(optlen);
  516. if (!opt)
  517. return -ENOMEM;
  518. if (optlen && copy_from_user(opt->opt.__data, data, optlen)) {
  519. kfree(opt);
  520. return -EFAULT;
  521. }
  522. return ip_options_get_finish(net, optp, opt, optlen);
  523. }
  524. int ip_options_get(struct net *net, struct ip_options_rcu **optp,
  525. unsigned char *data, int optlen)
  526. {
  527. struct ip_options_rcu *opt = ip_options_get_alloc(optlen);
  528. if (!opt)
  529. return -ENOMEM;
  530. if (optlen)
  531. memcpy(opt->opt.__data, data, optlen);
  532. return ip_options_get_finish(net, optp, opt, optlen);
  533. }
  534. void ip_forward_options(struct sk_buff *skb)
  535. {
  536. struct ip_options *opt = &(IPCB(skb)->opt);
  537. unsigned char *optptr;
  538. struct rtable *rt = skb_rtable(skb);
  539. unsigned char *raw = skb_network_header(skb);
  540. if (opt->rr_needaddr) {
  541. optptr = (unsigned char *)raw + opt->rr;
  542. ip_rt_get_source(&optptr[optptr[2]-5], skb, rt);
  543. opt->is_changed = 1;
  544. }
  545. if (opt->srr_is_hit) {
  546. int srrptr, srrspace;
  547. optptr = raw + opt->srr;
  548. for ( srrptr = optptr[2], srrspace = optptr[1];
  549. srrptr <= srrspace;
  550. srrptr += 4
  551. ) {
  552. if (srrptr + 3 > srrspace)
  553. break;
  554. if (memcmp(&opt->nexthop, &optptr[srrptr-1], 4) == 0)
  555. break;
  556. }
  557. if (srrptr + 3 <= srrspace) {
  558. opt->is_changed = 1;
  559. ip_hdr(skb)->daddr = opt->nexthop;
  560. ip_rt_get_source(&optptr[srrptr-1], skb, rt);
  561. optptr[2] = srrptr+4;
  562. } else {
  563. net_crit_ratelimited("%s(): Argh! Destination lost!\n",
  564. __func__);
  565. }
  566. if (opt->ts_needaddr) {
  567. optptr = raw + opt->ts;
  568. ip_rt_get_source(&optptr[optptr[2]-9], skb, rt);
  569. opt->is_changed = 1;
  570. }
  571. }
  572. if (opt->is_changed) {
  573. opt->is_changed = 0;
  574. ip_send_check(ip_hdr(skb));
  575. }
  576. }
  577. int ip_options_rcv_srr(struct sk_buff *skb)
  578. {
  579. struct ip_options *opt = &(IPCB(skb)->opt);
  580. int srrspace, srrptr;
  581. __be32 nexthop;
  582. struct iphdr *iph = ip_hdr(skb);
  583. unsigned char *optptr = skb_network_header(skb) + opt->srr;
  584. struct rtable *rt = skb_rtable(skb);
  585. struct rtable *rt2;
  586. unsigned long orefdst;
  587. int err;
  588. if (!rt)
  589. return 0;
  590. if (skb->pkt_type != PACKET_HOST)
  591. return -EINVAL;
  592. if (rt->rt_type == RTN_UNICAST) {
  593. if (!opt->is_strictroute)
  594. return 0;
  595. icmp_send(skb, ICMP_PARAMETERPROB, 0, htonl(16<<24));
  596. return -EINVAL;
  597. }
  598. if (rt->rt_type != RTN_LOCAL)
  599. return -EINVAL;
  600. for (srrptr = optptr[2], srrspace = optptr[1]; srrptr <= srrspace; srrptr += 4) {
  601. if (srrptr + 3 > srrspace) {
  602. icmp_send(skb, ICMP_PARAMETERPROB, 0, htonl((opt->srr+2)<<24));
  603. return -EINVAL;
  604. }
  605. memcpy(&nexthop, &optptr[srrptr-1], 4);
  606. orefdst = skb->_skb_refdst;
  607. skb_dst_set(skb, NULL);
  608. err = ip_route_input(skb, nexthop, iph->saddr, iph->tos, skb->dev);
  609. rt2 = skb_rtable(skb);
  610. if (err || (rt2->rt_type != RTN_UNICAST && rt2->rt_type != RTN_LOCAL)) {
  611. skb_dst_drop(skb);
  612. skb->_skb_refdst = orefdst;
  613. return -EINVAL;
  614. }
  615. refdst_drop(orefdst);
  616. if (rt2->rt_type != RTN_LOCAL)
  617. break;
  618. /* Superfast 8) loopback forward */
  619. iph->daddr = nexthop;
  620. opt->is_changed = 1;
  621. }
  622. if (srrptr <= srrspace) {
  623. opt->srr_is_hit = 1;
  624. opt->nexthop = nexthop;
  625. opt->is_changed = 1;
  626. }
  627. return 0;
  628. }
  629. EXPORT_SYMBOL(ip_options_rcv_srr);