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

Function key_sp2msg

freebsd/netipsec/key.c:1775–1844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1773}
1774
1775int
1776key_sp2msg(struct secpolicy *sp, void *request, size_t *len)
1777{
1778 struct sadb_x_ipsecrequest *xisr;
1779 struct sadb_x_policy *xpl;
1780 struct ipsecrequest *isr;
1781 size_t xlen, ilen;
1782 caddr_t p;
1783 int error, i;
1784
1785 IPSEC_ASSERT(sp != NULL, ("null policy"));
1786
1787 xlen = sizeof(*xpl);
1788 if (*len < xlen)
1789 return (EINVAL);
1790
1791 error = 0;
1792 bzero(request, *len);
1793 xpl = (struct sadb_x_policy *)request;
1794 xpl->sadb_x_policy_exttype = SADB_X_EXT_POLICY;
1795 xpl->sadb_x_policy_type = sp->policy;
1796 xpl->sadb_x_policy_dir = sp->spidx.dir;
1797 xpl->sadb_x_policy_id = sp->id;
1798 xpl->sadb_x_policy_priority = sp->priority;
1799 switch (sp->state) {
1800 case IPSEC_SPSTATE_IFNET:
1801 xpl->sadb_x_policy_scope = IPSEC_POLICYSCOPE_IFNET;
1802 break;
1803 case IPSEC_SPSTATE_PCB:
1804 xpl->sadb_x_policy_scope = IPSEC_POLICYSCOPE_PCB;
1805 break;
1806 default:
1807 xpl->sadb_x_policy_scope = IPSEC_POLICYSCOPE_GLOBAL;
1808 }
1809
1810 /* if is the policy for ipsec ? */
1811 if (sp->policy == IPSEC_POLICY_IPSEC) {
1812 p = (caddr_t)xpl + sizeof(*xpl);
1813 for (i = 0; i < sp->tcount; i++) {
1814 isr = sp->req[i];
1815 ilen = PFKEY_ALIGN8(sizeof(*xisr) +
1816 isr->saidx.src.sa.sa_len +
1817 isr->saidx.dst.sa.sa_len);
1818 xlen += ilen;
1819 if (xlen > *len) {
1820 error = ENOBUFS;
1821 /* Calculate needed size */
1822 continue;
1823 }
1824 xisr = (struct sadb_x_ipsecrequest *)p;
1825 xisr->sadb_x_ipsecrequest_len = ilen;
1826 xisr->sadb_x_ipsecrequest_proto = isr->saidx.proto;
1827 xisr->sadb_x_ipsecrequest_mode = isr->saidx.mode;
1828 xisr->sadb_x_ipsecrequest_level = isr->level;
1829 xisr->sadb_x_ipsecrequest_reqid = isr->saidx.reqid;
1830
1831 p += sizeof(*xisr);
1832 bcopy(&isr->saidx.src, p, isr->saidx.src.sa.sa_len);

Callers 2

key_sp2mbufFunction · 0.85
ipsec_get_pcbpolicyFunction · 0.85

Calls 1

bzeroFunction · 0.85

Tested by

no test coverage detected