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

Function key_setsaval

freebsd/netipsec/key.c:3270–3529  ·  view source on GitHub ↗

* copy SA values from PF_KEY message except *SPI, SEQ, PID and TYPE*. * You must update these if need. Expects only LARVAL SAs. * OUT: 0: success. * !0: failure. */

Source from the content-addressed store, hash-verified

3268 * !0: failure.
3269 */
3270static int
3271key_setsaval(struct secasvar *sav, const struct sadb_msghdr *mhp)
3272{
3273 const struct sadb_sa *sa0;
3274 const struct sadb_key *key0;
3275 uint32_t replay;
3276 size_t len;
3277 int error;
3278
3279 IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
3280 IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
3281 IPSEC_ASSERT(sav->state == SADB_SASTATE_LARVAL,
3282 ("Attempt to update non LARVAL SA"));
3283
3284 /* XXX rewrite */
3285 error = key_setident(sav->sah, mhp);
3286 if (error != 0)
3287 goto fail;
3288
3289 /* SA */
3290 if (!SADB_CHECKHDR(mhp, SADB_EXT_SA)) {
3291 if (SADB_CHECKLEN(mhp, SADB_EXT_SA)) {
3292 error = EINVAL;
3293 goto fail;
3294 }
3295 sa0 = (const struct sadb_sa *)mhp->ext[SADB_EXT_SA];
3296 sav->alg_auth = sa0->sadb_sa_auth;
3297 sav->alg_enc = sa0->sadb_sa_encrypt;
3298 sav->flags = sa0->sadb_sa_flags;
3299 if ((sav->flags & SADB_KEY_FLAGS_MAX) != sav->flags) {
3300 ipseclog((LOG_DEBUG,
3301 "%s: invalid sa_flags 0x%08x.\n", __func__,
3302 sav->flags));
3303 error = EINVAL;
3304 goto fail;
3305 }
3306
3307 /* Optional replay window */
3308 replay = 0;
3309 if ((sa0->sadb_sa_flags & SADB_X_EXT_OLD) == 0)
3310 replay = sa0->sadb_sa_replay;
3311 if (!SADB_CHECKHDR(mhp, SADB_X_EXT_SA_REPLAY)) {
3312 if (SADB_CHECKLEN(mhp, SADB_X_EXT_SA_REPLAY)) {
3313 error = EINVAL;
3314 goto fail;
3315 }
3316 replay = ((const struct sadb_x_sa_replay *)
3317 mhp->ext[SADB_X_EXT_SA_REPLAY])->sadb_x_sa_replay_replay;
3318
3319 if (replay > UINT32_MAX - 32) {
3320 ipseclog((LOG_DEBUG,
3321 "%s: replay window too big.\n", __func__));
3322 error = EINVAL;
3323 goto fail;
3324 }
3325
3326 replay = (replay + 7) >> 3;
3327 }

Callers 2

key_newsavFunction · 0.85
key_updateFunction · 0.85

Calls 7

key_setidentFunction · 0.85
mallocFunction · 0.85
key_dup_keymsgFunction · 0.85
xform_initFunction · 0.85
key_setnattFunction · 0.85
key_updatelifetimesFunction · 0.85
key_cleansavFunction · 0.85

Tested by

no test coverage detected