* Just introspect the header enough to fire off a seqno ack and validate * length fits. */
| 352 | * length fits. |
| 353 | */ |
| 354 | static void |
| 355 | debugnet_handle_rx_msg(struct debugnet_pcb *pcb, struct mbuf **mb) |
| 356 | { |
| 357 | const struct debugnet_msg_hdr *dnh; |
| 358 | struct mbuf *m; |
| 359 | int error; |
| 360 | |
| 361 | m = *mb; |
| 362 | |
| 363 | if (m->m_pkthdr.len < sizeof(*dnh)) { |
| 364 | DNETDEBUG("ignoring small debugnet_msg packet\n"); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | /* Get ND header. */ |
| 369 | if (m->m_len < sizeof(*dnh)) { |
| 370 | m = m_pullup(m, sizeof(*dnh)); |
| 371 | *mb = m; |
| 372 | if (m == NULL) { |
| 373 | DNETDEBUG("m_pullup failed\n"); |
| 374 | return; |
| 375 | } |
| 376 | } |
| 377 | dnh = mtod(m, const void *); |
| 378 | |
| 379 | if (ntohl(dnh->mh_len) + sizeof(*dnh) > m->m_pkthdr.len) { |
| 380 | DNETDEBUG("Dropping short packet.\n"); |
| 381 | return; |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * If the issue is transient (ENOBUFS), sender should resend. If |
| 386 | * non-transient (like driver objecting to rx -> tx from the same |
| 387 | * thread), not much else we can do. |
| 388 | */ |
| 389 | error = debugnet_ack_output(pcb, dnh->mh_seqno); |
| 390 | if (error != 0) |
| 391 | return; |
| 392 | |
| 393 | if (ntohl(dnh->mh_type) == DEBUGNET_FINISHED) { |
| 394 | printf("Remote shut down the connection on us!\n"); |
| 395 | pcb->dp_state = DN_STATE_REMOTE_CLOSED; |
| 396 | |
| 397 | /* |
| 398 | * Continue through to the user handler so they are signalled |
| 399 | * not to wait for further rx. |
| 400 | */ |
| 401 | } |
| 402 | |
| 403 | pcb->dp_rx_handler(pcb, mb); |
| 404 | } |
| 405 | |
| 406 | static void |
| 407 | debugnet_handle_ack(struct debugnet_pcb *pcb, struct mbuf **mb, uint16_t sport) |
no test coverage detected