* Receive data */
| 436 | * Receive data |
| 437 | */ |
| 438 | static int |
| 439 | cisco_input(sc_p sc, item_p item) |
| 440 | { |
| 441 | const struct cisco_header *h; |
| 442 | struct cisco_header hdrbuf; |
| 443 | struct protoent *pep; |
| 444 | struct mbuf *m; |
| 445 | int error = 0; |
| 446 | |
| 447 | /* Get data */ |
| 448 | m = NGI_M(item); |
| 449 | |
| 450 | /* Sanity check header length */ |
| 451 | if (m->m_pkthdr.len < sizeof(*h)) { |
| 452 | error = EINVAL; |
| 453 | goto drop; |
| 454 | } |
| 455 | |
| 456 | /* Get cisco header */ |
| 457 | if (m->m_len >= sizeof(*h)) /* the common case */ |
| 458 | h = mtod(m, const struct cisco_header *); |
| 459 | else { |
| 460 | m_copydata(m, 0, sizeof(*h), (caddr_t)&hdrbuf); |
| 461 | h = &hdrbuf; |
| 462 | } |
| 463 | m_adj(m, sizeof(*h)); |
| 464 | |
| 465 | /* Check header address */ |
| 466 | switch (h->address) { |
| 467 | default: /* Invalid Cisco packet. */ |
| 468 | goto drop; |
| 469 | case CISCO_UNICAST: |
| 470 | case CISCO_MULTICAST: |
| 471 | /* Don't check the control field here (RFC 1547). */ |
| 472 | switch (ntohs(h->protocol)) { |
| 473 | default: |
| 474 | goto drop; |
| 475 | case CISCO_KEEPALIVE: |
| 476 | { |
| 477 | const struct cisco_packet *p; |
| 478 | struct cisco_packet pktbuf; |
| 479 | |
| 480 | /* Sanity check packet length */ |
| 481 | if (m->m_pkthdr.len < sizeof(*p)) { |
| 482 | error = EINVAL; |
| 483 | goto drop; |
| 484 | } |
| 485 | |
| 486 | /* Get cisco packet */ |
| 487 | if (m->m_len >= sizeof(*p)) /* the common case */ |
| 488 | p = mtod(m, const struct cisco_packet *); |
| 489 | else { |
| 490 | m_copydata(m, 0, sizeof(*p), (caddr_t)&pktbuf); |
| 491 | p = &pktbuf; |
| 492 | } |
| 493 | |
| 494 | /* Check packet type */ |
| 495 | switch (ntohl(p->type)) { |
no test coverage detected