-/* XXX this interface should be obsoleted. */
-int
-key_sendup(so, msg, len, target)
- struct socket *so;
- struct sadb_msg *msg;
- u_int len;
- int target; /*target of the resulting message*/
-{
- struct mbuf *m, *n, *mprev;
- int tlen;
-
- /* sanity check */
- if (so == 0 || msg == 0)
- panic("key_sendup: NULL pointer was passed.\n");
-
- KEYDEBUG(KEYDEBUG_KEY_DUMP,
- printf("key_sendup: \n");
- kdebug_sadb(msg));
-
- /*
- * we increment statistics here, just in case we have ENOBUFS
- * in this function.
- */
- pfkeystat.in_total++;
- pfkeystat.in_bytes += len;
- pfkeystat.in_msgtype[msg->sadb_msg_type]++;
-
- /*
- * Get mbuf chain whenever possible (not clusters),
- * to save socket buffer. We'll be generating many SADB_ACQUIRE
- * messages to listening key sockets. If we simply allocate clusters,
- * sbappendaddr() will raise ENOBUFS due to too little sbspace().
- * sbspace() computes # of actual data bytes AND mbuf region.
- *
- * TODO: SADB_ACQUIRE filters should be implemented.
- */
- tlen = len;
- m = mprev = NULL;
- while (tlen > 0) {
- if (tlen == len) {
- MGETHDR(n, M_DONTWAIT, MT_DATA);
- n->m_len = MHLEN;
- } else {
- MGET(n, M_DONTWAIT, MT_DATA);
- n->m_len = MLEN;
- }
- if (!n) {
- pfkeystat.in_nomem++;
- return ENOBUFS;
- }
- if (tlen >= MCLBYTES) { /*XXX better threshold? */
- MCLGET(n, M_DONTWAIT);
- if ((n->m_flags & M_EXT) == 0) {
- m_free(n);
- m_freem(m);
- pfkeystat.in_nomem++;
- return ENOBUFS;
- }
- n->m_len = MCLBYTES;
- }
-
- if (tlen < n->m_len)
- n->m_len = tlen;
- n->m_next = NULL;
- if (m == NULL)
- m = mprev = n;
- else {
- mprev->m_next = n;
- mprev = n;
- }
- tlen -= n->m_len;
- n = NULL;
- }
- m->m_pkthdr.len = len;
- m->m_pkthdr.rcvif = NULL;
- m_copyback(m, 0, len, (caddr_t)msg);
-
- /* avoid duplicated statistics */
- pfkeystat.in_total--;
- pfkeystat.in_bytes -= len;
- pfkeystat.in_msgtype[msg->sadb_msg_type]--;
-
- return key_sendup_mbuf(so, m, target);
-}