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

Function ipsec_set_pcbpolicy

freebsd/netipsec/ipsec_pcb.c:271–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271static int
272ipsec_set_pcbpolicy(struct inpcb *inp, struct ucred *cred,
273 void *request, size_t len)
274{
275 struct sadb_x_policy *xpl;
276 struct secpolicy **spp, *newsp;
277 int error, flags;
278
279 xpl = (struct sadb_x_policy *)request;
280 /* Select direction. */
281 switch (xpl->sadb_x_policy_dir) {
282 case IPSEC_DIR_INBOUND:
283 case IPSEC_DIR_OUTBOUND:
284 break;
285 default:
286 ipseclog((LOG_ERR, "%s: invalid direction=%u\n", __func__,
287 xpl->sadb_x_policy_dir));
288 return (EINVAL);
289 }
290 /*
291 * Privileged sockets are allowed to set own security policy
292 * and configure IPsec bypass. Unprivileged sockets only can
293 * have ENTRUST policy.
294 */
295 switch (xpl->sadb_x_policy_type) {
296 case IPSEC_POLICY_IPSEC:
297 case IPSEC_POLICY_BYPASS:
298 if (cred != NULL &&
299 priv_check_cred(cred, PRIV_NETINET_IPSEC) != 0)
300 return (EACCES);
301 /* Allocate new SP entry. */
302 newsp = key_msg2sp(xpl, len, &error);
303 if (newsp == NULL)
304 return (error);
305 newsp->state = IPSEC_SPSTATE_PCB;
306 newsp->spidx.ul_proto = IPSEC_ULPROTO_ANY;
307#ifdef INET
308 if (inp->inp_vflag & INP_IPV4) {
309 newsp->spidx.src.sin.sin_family =
310 newsp->spidx.dst.sin.sin_family = AF_INET;
311 newsp->spidx.src.sin.sin_len =
312 newsp->spidx.dst.sin.sin_len =
313 sizeof(struct sockaddr_in);
314 }
315#endif
316#ifdef INET6
317 if (inp->inp_vflag & INP_IPV6) {
318 newsp->spidx.src.sin6.sin6_family =
319 newsp->spidx.dst.sin6.sin6_family = AF_INET6;
320 newsp->spidx.src.sin6.sin6_len =
321 newsp->spidx.dst.sin6.sin6_len =
322 sizeof(struct sockaddr_in6);
323 }
324#endif
325 break;
326 case IPSEC_POLICY_ENTRUST:
327 /* We just use NULL pointer for ENTRUST policy */
328 newsp = NULL;

Callers 1

ipsec_control_pcbpolicyFunction · 0.85

Calls 5

key_msg2spFunction · 0.85
key_freespFunction · 0.85
kdebug_secpolicyFunction · 0.85
priv_check_credFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected