* Destination options header processing. */
| 62 | * Destination options header processing. |
| 63 | */ |
| 64 | int |
| 65 | dest6_input(struct mbuf **mp, int *offp, int proto) |
| 66 | { |
| 67 | struct mbuf *m; |
| 68 | int off, dstoptlen, optlen; |
| 69 | struct ip6_dest *dstopts; |
| 70 | u_int8_t *opt; |
| 71 | |
| 72 | m = *mp; |
| 73 | off = *offp; |
| 74 | |
| 75 | /* Validation of the length of the header. */ |
| 76 | if (m->m_len < off + sizeof(*dstopts)) { |
| 77 | m = m_pullup(m, off + sizeof(*dstopts)); |
| 78 | if (m == NULL) { |
| 79 | IP6STAT_INC(ip6s_exthdrtoolong); |
| 80 | *mp = m; |
| 81 | return (IPPROTO_DONE); |
| 82 | } |
| 83 | } |
| 84 | dstopts = (struct ip6_dest *)(mtod(m, caddr_t) + off); |
| 85 | dstoptlen = (dstopts->ip6d_len + 1) << 3; |
| 86 | |
| 87 | if (m->m_len < off + dstoptlen) { |
| 88 | m = m_pullup(m, off + dstoptlen); |
| 89 | if (m == NULL) { |
| 90 | IP6STAT_INC(ip6s_exthdrtoolong); |
| 91 | *mp = m; |
| 92 | return (IPPROTO_DONE); |
| 93 | } |
| 94 | } |
| 95 | dstopts = (struct ip6_dest *)(mtod(m, caddr_t) + off); |
| 96 | off += dstoptlen; |
| 97 | dstoptlen -= sizeof(struct ip6_dest); |
| 98 | opt = (u_int8_t *)dstopts + sizeof(struct ip6_dest); |
| 99 | |
| 100 | /* search header for all options. */ |
| 101 | for (; dstoptlen > 0; dstoptlen -= optlen, opt += optlen) { |
| 102 | if (*opt != IP6OPT_PAD1 && |
| 103 | (dstoptlen < IP6OPT_MINLEN || *(opt + 1) + 2 > dstoptlen)) { |
| 104 | IP6STAT_INC(ip6s_toosmall); |
| 105 | goto bad; |
| 106 | } |
| 107 | |
| 108 | switch (*opt) { |
| 109 | case IP6OPT_PAD1: |
| 110 | optlen = 1; |
| 111 | break; |
| 112 | case IP6OPT_PADN: |
| 113 | optlen = *(opt + 1) + 2; |
| 114 | break; |
| 115 | default: /* unknown option */ |
| 116 | optlen = ip6_unknown_opt(opt, m, |
| 117 | opt - mtod(m, u_int8_t *)); |
| 118 | if (optlen == -1) { |
| 119 | *mp = NULL; |
| 120 | return (IPPROTO_DONE); |
| 121 | } |
nothing calls this directly
no test coverage detected