diff options
author | ume <ume@FreeBSD.org> | 2003-11-02 09:13:33 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2003-11-02 09:13:33 +0000 |
commit | e1581c03b6f31a7685e64b5c4319f36f27f82380 (patch) | |
tree | 1a4bbbcf96e1b331686ba0692d0395fdb103d362 | |
parent | 7efdcbb8169eefba76f3e422589015af1683fffd (diff) | |
download | FreeBSD-src-e1581c03b6f31a7685e64b5c4319f36f27f82380.zip FreeBSD-src-e1581c03b6f31a7685e64b5c4319f36f27f82380.tar.gz |
- do not quit from key_sendup() even if writes to non-target
socket fails.
- remove an unneeded function.
- fix pfkey stat.
- fix comment.
Obtained from: KAME
-rw-r--r-- | sys/netkey/keysock.c | 98 | ||||
-rw-r--r-- | sys/netkey/keysock.h | 7 |
2 files changed, 10 insertions, 95 deletions
diff --git a/sys/netkey/keysock.c b/sys/netkey/keysock.c index ec71540..376841d 100644 --- a/sys/netkey/keysock.c +++ b/sys/netkey/keysock.c @@ -1,4 +1,4 @@ -/* $KAME: keysock.c,v 1.25 2001/08/13 20:07:41 itojun Exp $ */ +/* $KAME: keysock.c,v 1.32 2003/08/22 05:45:08 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -154,7 +154,6 @@ key_sendup0(rp, m, promisc) m = m_pullup(m, sizeof(struct sadb_msg)); if (!m) { pfkeystat.in_nomem++; - m_freem(m); return ENOBUFS; } m->m_pkthdr.len += sizeof(*pmsg); @@ -180,91 +179,6 @@ key_sendup0(rp, m, promisc) return error; } -/* 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."); - - 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); -} - /* so can be NULL if target != KEY_SENDUP_ONE */ int key_sendup_mbuf(so, m, target) @@ -350,10 +264,12 @@ key_sendup_mbuf(so, m, target) return ENOBUFS; } - if ((error = key_sendup0(rp, n, 0)) != 0) { - m_freem(m); - return error; - } + /* + * ignore error even if queue is full. PF_KEY does not + * guarantee the delivery of the message. + * this is important when target == KEY_SENDUP_ALL. + */ + key_sendup0(rp, n, 0); n = NULL; } diff --git a/sys/netkey/keysock.h b/sys/netkey/keysock.h index 8d439b9..5ea58f5 100644 --- a/sys/netkey/keysock.h +++ b/sys/netkey/keysock.h @@ -1,5 +1,5 @@ /* $FreeBSD$ */ -/* $KAME: keysock.h,v 1.8 2000/03/27 05:11:06 sumikawa Exp $ */ +/* $KAME: keysock.h,v 1.9 2002/03/21 14:00:14 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -35,7 +35,7 @@ /* statistics for pfkey socket */ struct pfkeystat { - /* kernel -> userland */ + /* userland -> kernel */ u_quad_t out_total; /* # of total calls */ u_quad_t out_bytes; /* total bytecount */ u_quad_t out_msgtype[256]; /* message type histogram */ @@ -48,7 +48,7 @@ struct pfkeystat { u_quad_t out_invexttype; /* invalid extension type */ u_quad_t out_invsatype; /* invalid sa type */ u_quad_t out_invaddr; /* invalid address extension */ - /* userland -> kernel */ + /* kernel -> userland */ u_quad_t in_total; /* # of total calls */ u_quad_t in_bytes; /* total bytecount */ u_quad_t in_msgtype[256]; /* message type histogram */ @@ -75,7 +75,6 @@ extern int key_output(struct mbuf *, ...); extern int key_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *); -extern int key_sendup(struct socket *, struct sadb_msg *, u_int, int); extern int key_sendup_mbuf(struct socket *, struct mbuf *, int); #endif /* _KERNEL */ |