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

Function key_setident

freebsd/netipsec/key.c:5835–5898  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5833}
5834
5835static int
5836key_setident(struct secashead *sah, const struct sadb_msghdr *mhp)
5837{
5838 const struct sadb_ident *idsrc, *iddst;
5839
5840 IPSEC_ASSERT(sah != NULL, ("null secashead"));
5841 IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
5842 IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
5843
5844 /* don't make buffer if not there */
5845 if (SADB_CHECKHDR(mhp, SADB_EXT_IDENTITY_SRC) &&
5846 SADB_CHECKHDR(mhp, SADB_EXT_IDENTITY_DST)) {
5847 sah->idents = NULL;
5848 sah->identd = NULL;
5849 return (0);
5850 }
5851
5852 if (SADB_CHECKHDR(mhp, SADB_EXT_IDENTITY_SRC) ||
5853 SADB_CHECKHDR(mhp, SADB_EXT_IDENTITY_DST)) {
5854 ipseclog((LOG_DEBUG, "%s: invalid identity.\n", __func__));
5855 return (EINVAL);
5856 }
5857
5858 idsrc = (const struct sadb_ident *)mhp->ext[SADB_EXT_IDENTITY_SRC];
5859 iddst = (const struct sadb_ident *)mhp->ext[SADB_EXT_IDENTITY_DST];
5860
5861 /* validity check */
5862 if (idsrc->sadb_ident_type != iddst->sadb_ident_type) {
5863 ipseclog((LOG_DEBUG, "%s: ident type mismatch.\n", __func__));
5864 return EINVAL;
5865 }
5866
5867 switch (idsrc->sadb_ident_type) {
5868 case SADB_IDENTTYPE_PREFIX:
5869 case SADB_IDENTTYPE_FQDN:
5870 case SADB_IDENTTYPE_USERFQDN:
5871 default:
5872 /* XXX do nothing */
5873 sah->idents = NULL;
5874 sah->identd = NULL;
5875 return 0;
5876 }
5877
5878 /* make structure */
5879 sah->idents = malloc(sizeof(struct secident), M_IPSEC_MISC, M_NOWAIT);
5880 if (sah->idents == NULL) {
5881 ipseclog((LOG_DEBUG, "%s: No more memory.\n", __func__));
5882 return ENOBUFS;
5883 }
5884 sah->identd = malloc(sizeof(struct secident), M_IPSEC_MISC, M_NOWAIT);
5885 if (sah->identd == NULL) {
5886 free(sah->idents, M_IPSEC_MISC);
5887 sah->idents = NULL;
5888 ipseclog((LOG_DEBUG, "%s: No more memory.\n", __func__));
5889 return ENOBUFS;
5890 }
5891 sah->idents->type = idsrc->sadb_ident_type;
5892 sah->idents->id = idsrc->sadb_ident_id;

Callers 1

key_setsavalFunction · 0.85

Calls 2

mallocFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected