* Copy options from ip to jp, omitting those not copied during * fragmentation. */
| 554 | * fragmentation. |
| 555 | */ |
| 556 | int |
| 557 | ip_optcopy(struct ip *ip, struct ip *jp) |
| 558 | { |
| 559 | u_char *cp, *dp; |
| 560 | int opt, optlen, cnt; |
| 561 | |
| 562 | cp = (u_char *)(ip + 1); |
| 563 | dp = (u_char *)(jp + 1); |
| 564 | cnt = (ip->ip_hl << 2) - sizeof (struct ip); |
| 565 | for (; cnt > 0; cnt -= optlen, cp += optlen) { |
| 566 | opt = cp[0]; |
| 567 | if (opt == IPOPT_EOL) |
| 568 | break; |
| 569 | if (opt == IPOPT_NOP) { |
| 570 | /* Preserve for IP mcast tunnel's LSRR alignment. */ |
| 571 | *dp++ = IPOPT_NOP; |
| 572 | optlen = 1; |
| 573 | continue; |
| 574 | } |
| 575 | |
| 576 | KASSERT(cnt >= IPOPT_OLEN + sizeof(*cp), |
| 577 | ("ip_optcopy: malformed ipv4 option")); |
| 578 | optlen = cp[IPOPT_OLEN]; |
| 579 | KASSERT(optlen >= IPOPT_OLEN + sizeof(*cp) && optlen <= cnt, |
| 580 | ("ip_optcopy: malformed ipv4 option")); |
| 581 | |
| 582 | /* Bogus lengths should have been caught by ip_dooptions. */ |
| 583 | if (optlen > cnt) |
| 584 | optlen = cnt; |
| 585 | if (IPOPT_COPIED(opt)) { |
| 586 | bcopy(cp, dp, optlen); |
| 587 | dp += optlen; |
| 588 | } |
| 589 | } |
| 590 | for (optlen = dp - (u_char *)(jp+1); optlen & 0x3; optlen++) |
| 591 | *dp++ = IPOPT_EOL; |
| 592 | return (optlen); |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * Set up IP options in pcb for insertion in output packets. Store in mbuf |
no outgoing calls
no test coverage detected