* Insert jumbo payload option. */
| 1323 | * Insert jumbo payload option. |
| 1324 | */ |
| 1325 | static int |
| 1326 | ip6_insert_jumboopt(struct ip6_exthdrs *exthdrs, u_int32_t plen) |
| 1327 | { |
| 1328 | struct mbuf *mopt; |
| 1329 | u_char *optbuf; |
| 1330 | u_int32_t v; |
| 1331 | |
| 1332 | #define JUMBOOPTLEN 8 /* length of jumbo payload option and padding */ |
| 1333 | |
| 1334 | /* |
| 1335 | * If there is no hop-by-hop options header, allocate new one. |
| 1336 | * If there is one but it doesn't have enough space to store the |
| 1337 | * jumbo payload option, allocate a cluster to store the whole options. |
| 1338 | * Otherwise, use it to store the options. |
| 1339 | */ |
| 1340 | if (exthdrs->ip6e_hbh == NULL) { |
| 1341 | mopt = m_get(M_NOWAIT, MT_DATA); |
| 1342 | if (mopt == NULL) |
| 1343 | return (ENOBUFS); |
| 1344 | mopt->m_len = JUMBOOPTLEN; |
| 1345 | optbuf = mtod(mopt, u_char *); |
| 1346 | optbuf[1] = 0; /* = ((JUMBOOPTLEN) >> 3) - 1 */ |
| 1347 | exthdrs->ip6e_hbh = mopt; |
| 1348 | } else { |
| 1349 | struct ip6_hbh *hbh; |
| 1350 | |
| 1351 | mopt = exthdrs->ip6e_hbh; |
| 1352 | if (M_TRAILINGSPACE(mopt) < JUMBOOPTLEN) { |
| 1353 | /* |
| 1354 | * XXX assumption: |
| 1355 | * - exthdrs->ip6e_hbh is not referenced from places |
| 1356 | * other than exthdrs. |
| 1357 | * - exthdrs->ip6e_hbh is not an mbuf chain. |
| 1358 | */ |
| 1359 | int oldoptlen = mopt->m_len; |
| 1360 | struct mbuf *n; |
| 1361 | |
| 1362 | /* |
| 1363 | * XXX: give up if the whole (new) hbh header does |
| 1364 | * not fit even in an mbuf cluster. |
| 1365 | */ |
| 1366 | if (oldoptlen + JUMBOOPTLEN > MCLBYTES) |
| 1367 | return (ENOBUFS); |
| 1368 | |
| 1369 | /* |
| 1370 | * As a consequence, we must always prepare a cluster |
| 1371 | * at this point. |
| 1372 | */ |
| 1373 | n = m_getcl(M_NOWAIT, MT_DATA, 0); |
| 1374 | if (n == NULL) |
| 1375 | return (ENOBUFS); |
| 1376 | n->m_len = oldoptlen + JUMBOOPTLEN; |
| 1377 | bcopy(mtod(mopt, caddr_t), mtod(n, caddr_t), |
| 1378 | oldoptlen); |
| 1379 | optbuf = mtod(n, caddr_t) + oldoptlen; |
| 1380 | m_freem(mopt); |
| 1381 | mopt = exthdrs->ip6e_hbh = n; |
| 1382 | } else { |
no test coverage detected