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

Function key_sendup_mbuf

freebsd/netipsec/keysock.c:176–263  ·  view source on GitHub ↗

so can be NULL if target != KEY_SENDUP_ONE */

Source from the content-addressed store, hash-verified

174
175/* so can be NULL if target != KEY_SENDUP_ONE */
176int
177key_sendup_mbuf(struct socket *so, struct mbuf *m, int target)
178{
179 struct mbuf *n;
180 struct keycb *kp;
181 struct rawcb *rp;
182 int error = 0;
183
184 KASSERT(m != NULL, ("NULL mbuf pointer was passed."));
185 KASSERT(so != NULL || target != KEY_SENDUP_ONE,
186 ("NULL socket pointer was passed."));
187 KASSERT(target == KEY_SENDUP_ONE || target == KEY_SENDUP_ALL ||
188 target == KEY_SENDUP_REGISTERED, ("Wrong target %d", target));
189
190 PFKEYSTAT_INC(in_total);
191 PFKEYSTAT_ADD(in_bytes, m->m_pkthdr.len);
192 if (m->m_len < sizeof(struct sadb_msg)) {
193 m = m_pullup(m, sizeof(struct sadb_msg));
194 if (m == NULL) {
195 PFKEYSTAT_INC(in_nomem);
196 return ENOBUFS;
197 }
198 }
199 if (m->m_len >= sizeof(struct sadb_msg)) {
200 struct sadb_msg *msg;
201 msg = mtod(m, struct sadb_msg *);
202 PFKEYSTAT_INC(in_msgtype[msg->sadb_msg_type]);
203 }
204 mtx_lock(&rawcb_mtx);
205 if (V_key_cb.any_count == 0) {
206 mtx_unlock(&rawcb_mtx);
207 m_freem(m);
208 return (0);
209 }
210 LIST_FOREACH(rp, &V_rawcb_list, list)
211 {
212 if (rp->rcb_proto.sp_family != PF_KEY)
213 continue;
214 if (rp->rcb_proto.sp_protocol
215 && rp->rcb_proto.sp_protocol != PF_KEY_V2) {
216 continue;
217 }
218
219 /*
220 * If you are in promiscuous mode, and when you get broadcasted
221 * reply, you'll get two PF_KEY messages.
222 * (based on pf_key@inner.net message on 14 Oct 1998)
223 */
224 kp = (struct keycb *)rp;
225 if (kp->kp_promisc) {
226 n = m_copym(m, 0, M_COPYALL, M_NOWAIT);
227 if (n != NULL)
228 key_sendup0(rp, n, 1);
229 else
230 PFKEYSTAT_INC(in_nomem);
231 }
232
233 /* the exact target will be processed later */

Callers 15

key_register_ifnetFunction · 0.85
key_unregister_ifnetFunction · 0.85
key_spdaddFunction · 0.85
key_spddeleteFunction · 0.85
key_spddelete2Function · 0.85
key_spdgetFunction · 0.85
key_spdacquireFunction · 0.85
key_spdflushFunction · 0.85
key_spddumpFunction · 0.85
key_spdexpireFunction · 0.85
key_getspiFunction · 0.85
key_updateaddressesFunction · 0.85

Calls 6

m_pullupFunction · 0.85
m_copymFunction · 0.85
key_sendup0Function · 0.85
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50
m_freemFunction · 0.50

Tested by

no test coverage detected