MCPcopy Create free account
hub / github.com/F-Stack/f-stack / key_register

Function key_register

freebsd/netipsec/key.c:7070–7217  ·  view source on GitHub ↗

* SADB_REGISTER processing. * If SATYPE_UNSPEC has been passed as satype, only return sabd_supported. * receive * * from the ikmpd, and register a socket to send PF_KEY messages, * and send * * to KMD by PF_KEY. * If socket is detached, must free from regnode. * * m will always be freed. */

Source from the content-addressed store, hash-verified

7068 * m will always be freed.
7069 */
7070static int
7071key_register(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp)
7072{
7073 struct secreg *reg, *newreg = NULL;
7074
7075 IPSEC_ASSERT(so != NULL, ("null socket"));
7076 IPSEC_ASSERT(m != NULL, ("null mbuf"));
7077 IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
7078 IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
7079
7080 /* check for invalid register message */
7081 if (mhp->msg->sadb_msg_satype >= sizeof(V_regtree)/sizeof(V_regtree[0]))
7082 return key_senderror(so, m, EINVAL);
7083
7084 /* When SATYPE_UNSPEC is specified, only return sabd_supported. */
7085 if (mhp->msg->sadb_msg_satype == SADB_SATYPE_UNSPEC)
7086 goto setmsg;
7087
7088 /* check whether existing or not */
7089 REGTREE_LOCK();
7090 LIST_FOREACH(reg, &V_regtree[mhp->msg->sadb_msg_satype], chain) {
7091 if (reg->so == so) {
7092 REGTREE_UNLOCK();
7093 ipseclog((LOG_DEBUG, "%s: socket exists already.\n",
7094 __func__));
7095 return key_senderror(so, m, EEXIST);
7096 }
7097 }
7098
7099 /* create regnode */
7100 newreg = malloc(sizeof(struct secreg), M_IPSEC_SAR, M_NOWAIT|M_ZERO);
7101 if (newreg == NULL) {
7102 REGTREE_UNLOCK();
7103 ipseclog((LOG_DEBUG, "%s: No more memory.\n", __func__));
7104 return key_senderror(so, m, ENOBUFS);
7105 }
7106
7107 newreg->so = so;
7108 ((struct keycb *)sotorawcb(so))->kp_registered++;
7109
7110 /* add regnode to regtree. */
7111 LIST_INSERT_HEAD(&V_regtree[mhp->msg->sadb_msg_satype], newreg, chain);
7112 REGTREE_UNLOCK();
7113
7114 setmsg:
7115 {
7116 struct mbuf *n;
7117 struct sadb_msg *newmsg;
7118 struct sadb_supported *sup;
7119 u_int len, alen, elen;
7120 int off;
7121 int i;
7122 struct sadb_alg *alg;
7123
7124 /* create new sadb_msg to reply. */
7125 alen = 0;
7126 for (i = 1; i <= SADB_AALG_MAX; i++) {
7127 if (auth_algorithm_lookup(i))

Callers

nothing calls this directly

Calls 8

key_senderrorFunction · 0.85
mallocFunction · 0.85
auth_algorithm_lookupFunction · 0.85
enc_algorithm_lookupFunction · 0.85
m_copydataFunction · 0.85
key_getsizes_ahFunction · 0.85
key_sendup_mbufFunction · 0.85
m_freemFunction · 0.50

Tested by

no test coverage detected