| 1571 | } |
| 1572 | |
| 1573 | static void |
| 1574 | pfsync_sendout(int schedswi, int c) |
| 1575 | { |
| 1576 | struct pfsync_softc *sc = V_pfsyncif; |
| 1577 | struct ifnet *ifp = sc->sc_ifp; |
| 1578 | struct mbuf *m; |
| 1579 | struct ip *ip; |
| 1580 | struct pfsync_header *ph; |
| 1581 | struct pfsync_subheader *subh; |
| 1582 | struct pf_state *st, *st_next; |
| 1583 | struct pfsync_upd_req_item *ur; |
| 1584 | struct pfsync_bucket *b = &sc->sc_buckets[c]; |
| 1585 | int offset; |
| 1586 | int q, count = 0; |
| 1587 | |
| 1588 | KASSERT(sc != NULL, ("%s: null sc", __func__)); |
| 1589 | KASSERT(b->b_len > PFSYNC_MINPKT, |
| 1590 | ("%s: sc_len %zu", __func__, b->b_len)); |
| 1591 | PFSYNC_BUCKET_LOCK_ASSERT(b); |
| 1592 | |
| 1593 | if (ifp->if_bpf == NULL && sc->sc_sync_if == NULL) { |
| 1594 | pfsync_drop(sc); |
| 1595 | return; |
| 1596 | } |
| 1597 | |
| 1598 | m = m_get2(max_linkhdr + b->b_len, M_NOWAIT, MT_DATA, M_PKTHDR); |
| 1599 | if (m == NULL) { |
| 1600 | if_inc_counter(sc->sc_ifp, IFCOUNTER_OERRORS, 1); |
| 1601 | V_pfsyncstats.pfsyncs_onomem++; |
| 1602 | return; |
| 1603 | } |
| 1604 | m->m_data += max_linkhdr; |
| 1605 | m->m_len = m->m_pkthdr.len = b->b_len; |
| 1606 | |
| 1607 | /* build the ip header */ |
| 1608 | ip = (struct ip *)m->m_data; |
| 1609 | bcopy(&sc->sc_template, ip, sizeof(*ip)); |
| 1610 | offset = sizeof(*ip); |
| 1611 | |
| 1612 | ip->ip_len = htons(m->m_pkthdr.len); |
| 1613 | ip_fillid(ip); |
| 1614 | |
| 1615 | /* build the pfsync header */ |
| 1616 | ph = (struct pfsync_header *)(m->m_data + offset); |
| 1617 | bzero(ph, sizeof(*ph)); |
| 1618 | offset += sizeof(*ph); |
| 1619 | |
| 1620 | ph->version = PFSYNC_VERSION; |
| 1621 | ph->len = htons(b->b_len - sizeof(*ip)); |
| 1622 | bcopy(V_pf_status.pf_chksum, ph->pfcksum, PF_MD5_DIGEST_LENGTH); |
| 1623 | |
| 1624 | /* walk the queues */ |
| 1625 | for (q = 0; q < PFSYNC_S_COUNT; q++) { |
| 1626 | if (TAILQ_EMPTY(&b->b_qs[q])) |
| 1627 | continue; |
| 1628 | |
| 1629 | subh = (struct pfsync_subheader *)(m->m_data + offset); |
| 1630 | offset += sizeof(*subh); |
no test coverage detected