* Retrieve incoming source route for use in replies, in the same form used * by setsockopt. The first hop is placed before the options, will be * removed later. */
| 423 | * removed later. |
| 424 | */ |
| 425 | struct mbuf * |
| 426 | ip_srcroute(struct mbuf *m0) |
| 427 | { |
| 428 | struct in_addr *p, *q; |
| 429 | struct mbuf *m; |
| 430 | struct ipopt_tag *opts; |
| 431 | |
| 432 | opts = (struct ipopt_tag *)m_tag_find(m0, PACKET_TAG_IPOPTIONS, NULL); |
| 433 | if (opts == NULL) |
| 434 | return (NULL); |
| 435 | |
| 436 | if (opts->ip_nhops == 0) |
| 437 | return (NULL); |
| 438 | m = m_get(M_NOWAIT, MT_DATA); |
| 439 | if (m == NULL) |
| 440 | return (NULL); |
| 441 | |
| 442 | #define OPTSIZ (sizeof(opts->ip_srcrt.nop) + sizeof(opts->ip_srcrt.srcopt)) |
| 443 | |
| 444 | /* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */ |
| 445 | m->m_len = opts->ip_nhops * sizeof(struct in_addr) + |
| 446 | sizeof(struct in_addr) + OPTSIZ; |
| 447 | |
| 448 | /* |
| 449 | * First, save first hop for return route. |
| 450 | */ |
| 451 | p = &(opts->ip_srcrt.route[opts->ip_nhops - 1]); |
| 452 | *(mtod(m, struct in_addr *)) = *p--; |
| 453 | |
| 454 | /* |
| 455 | * Copy option fields and padding (nop) to mbuf. |
| 456 | */ |
| 457 | opts->ip_srcrt.nop = IPOPT_NOP; |
| 458 | opts->ip_srcrt.srcopt[IPOPT_OFFSET] = IPOPT_MINOFF; |
| 459 | (void)memcpy(mtod(m, caddr_t) + sizeof(struct in_addr), |
| 460 | &(opts->ip_srcrt.nop), OPTSIZ); |
| 461 | q = (struct in_addr *)(mtod(m, caddr_t) + |
| 462 | sizeof(struct in_addr) + OPTSIZ); |
| 463 | #undef OPTSIZ |
| 464 | /* |
| 465 | * Record return path as an IP source route, reversing the path |
| 466 | * (pointers are now aligned). |
| 467 | */ |
| 468 | while (p >= opts->ip_srcrt.route) { |
| 469 | *q++ = *p--; |
| 470 | } |
| 471 | /* |
| 472 | * Last hop goes to final destination. |
| 473 | */ |
| 474 | *q = opts->ip_srcrt.dst; |
| 475 | m_tag_delete(m0, (struct m_tag *)opts); |
| 476 | return (m); |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Strip out IP options, at higher level protocol in the kernel. |
no test coverage detected