ip_options.c 15 KB

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