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

Function key_spdadd

freebsd/netipsec/key.c:1938–2110  ·  view source on GitHub ↗

* SADB_X_SPDADD, SADB_X_SPDSETIDX or SADB_X_SPDUPDATE processing * add an entry to SP database, when received * * from the user(?). * Adding to SP database, * and send * * to the socket which was send. * * SPDADD set a unique policy entry. * SPDSETIDX like SPDADD without a part of policy requests.

Source from the content-addressed store, hash-verified

1936 * m will always be freed.
1937 */
1938static int
1939key_spdadd(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp)
1940{
1941 struct secpolicyindex spidx;
1942 struct sadb_address *src0, *dst0;
1943 struct sadb_x_policy *xpl0, *xpl;
1944 struct sadb_lifetime *lft = NULL;
1945 struct secpolicy *newsp;
1946 int error;
1947
1948 IPSEC_ASSERT(so != NULL, ("null socket"));
1949 IPSEC_ASSERT(m != NULL, ("null mbuf"));
1950 IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
1951 IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
1952
1953 if (SADB_CHECKHDR(mhp, SADB_EXT_ADDRESS_SRC) ||
1954 SADB_CHECKHDR(mhp, SADB_EXT_ADDRESS_DST) ||
1955 SADB_CHECKHDR(mhp, SADB_X_EXT_POLICY)) {
1956 ipseclog((LOG_DEBUG,
1957 "%s: invalid message: missing required header.\n",
1958 __func__));
1959 return key_senderror(so, m, EINVAL);
1960 }
1961 if (SADB_CHECKLEN(mhp, SADB_EXT_ADDRESS_SRC) ||
1962 SADB_CHECKLEN(mhp, SADB_EXT_ADDRESS_DST) ||
1963 SADB_CHECKLEN(mhp, SADB_X_EXT_POLICY)) {
1964 ipseclog((LOG_DEBUG,
1965 "%s: invalid message: wrong header size.\n", __func__));
1966 return key_senderror(so, m, EINVAL);
1967 }
1968 if (!SADB_CHECKHDR(mhp, SADB_EXT_LIFETIME_HARD)) {
1969 if (SADB_CHECKLEN(mhp, SADB_EXT_LIFETIME_HARD)) {
1970 ipseclog((LOG_DEBUG,
1971 "%s: invalid message: wrong header size.\n",
1972 __func__));
1973 return key_senderror(so, m, EINVAL);
1974 }
1975 lft = (struct sadb_lifetime *)mhp->ext[SADB_EXT_LIFETIME_HARD];
1976 }
1977
1978 src0 = (struct sadb_address *)mhp->ext[SADB_EXT_ADDRESS_SRC];
1979 dst0 = (struct sadb_address *)mhp->ext[SADB_EXT_ADDRESS_DST];
1980 xpl0 = (struct sadb_x_policy *)mhp->ext[SADB_X_EXT_POLICY];
1981
1982 /* check the direciton */
1983 switch (xpl0->sadb_x_policy_dir) {
1984 case IPSEC_DIR_INBOUND:
1985 case IPSEC_DIR_OUTBOUND:
1986 break;
1987 default:
1988 ipseclog((LOG_DEBUG, "%s: invalid SP direction.\n", __func__));
1989 return key_senderror(so, m, EINVAL);
1990 }
1991 /* key_spdadd() accepts DISCARD, NONE and IPSEC. */
1992 if (xpl0->sadb_x_policy_type != IPSEC_POLICY_DISCARD &&
1993 xpl0->sadb_x_policy_type != IPSEC_POLICY_NONE &&
1994 xpl0->sadb_x_policy_type != IPSEC_POLICY_IPSEC) {
1995 ipseclog((LOG_DEBUG, "%s: invalid policy type.\n", __func__));

Callers

nothing calls this directly

Calls 15

key_senderrorFunction · 0.85
key_checksockaddrsFunction · 0.85
key_getspFunction · 0.85
kdebug_secpolicyFunction · 0.85
key_unlinkFunction · 0.85
key_freespFunction · 0.85
key_msg2spFunction · 0.85
key_getnewspidFunction · 0.85
key_insertspFunction · 0.85
spdcache_clearFunction · 0.85
key_gather_mbufFunction · 0.85
m_pullupFunction · 0.85

Tested by

no test coverage detected