if (sa->tdb_amxkey) i+= PADUP(sa->tdb_amxkeylen) + sizeof(struct sadb_key);  if (sa->tdb_emxkey) i+= PADUP(sa->tdb_emxkeylen) + sizeof(struct sadb_key);
pfkeyv2_get(struct tdb *sa, void **headers, void **buffer){    int rval, i;    void *p;    /* Find how much space we need */    i = sizeof(struct sadb_sa) + sizeof(struct sadb_lifetime);    if (sa->tdb_soft_allocations || sa->tdb_soft_bytes ||	sa->tdb_soft_timeout || sa->tdb_soft_first_use)      i += sizeof(struct sadb_lifetime);    if (sa->tdb_exp_allocations || sa->tdb_exp_bytes ||	sa->tdb_exp_timeout || sa->tdb_exp_first_use)      i += sizeof(struct sadb_lifetime);    if (sa->tdb_src.sa.sa_family)      i += sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_src.sa));    if (sa->tdb_dst.sa.sa_family)      i += sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_dst.sa));    if (sa->tdb_proxy.sa.sa_family)      i += sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_proxy.sa));    if (sa->tdb_srcid)      i += PADUP(sa->tdb_srcid->ref_len) + sizeof(struct sadb_ident);    if (sa->tdb_dstid)      i += PADUP(sa->tdb_dstid->ref_len) + sizeof(struct sadb_ident);    if (sa->tdb_local_cred)      i += PADUP(sa->tdb_local_cred->ref_len) + sizeof(struct sadb_x_cred);    if (sa->tdb_remote_cred)      i += PADUP(sa->tdb_remote_cred->ref_len) + sizeof(struct sadb_x_cred);    if (sa->tdb_local_auth)      i += PADUP(sa->tdb_local_auth->ref_len) + sizeof(struct sadb_x_cred);    if (sa->tdb_remote_auth)      i += PADUP(sa->tdb_remote_auth->ref_len) + sizeof(struct sadb_x_cred);    if (!(p = malloc(i, M_PFKEY, M_DONTWAIT)))    {	rval = ENOMEM;	goto ret;    }    else    {	*buffer = p;	bzero(p, i);    }    headers[SADB_EXT_SA] = p;    export_sa(&p, sa);  /* Export SA information (mostly flags) */    /* Export lifetimes where applicable */    headers[SADB_EXT_LIFETIME_CURRENT] = p;    export_lifetime(&p, sa, PFKEYV2_LIFETIME_CURRENT);    if (sa->tdb_soft_allocations || sa->tdb_soft_bytes ||	sa->tdb_soft_first_use || sa->tdb_soft_timeout)    {	headers[SADB_EXT_LIFETIME_SOFT] = p;	export_lifetime(&p, sa, PFKEYV2_LIFETIME_SOFT);    }    if (sa->tdb_exp_allocations || sa->tdb_exp_bytes ||	sa->tdb_exp_first_use || sa->tdb_exp_timeout)    {	headers[SADB_EXT_LIFETIME_HARD] = p;	export_lifetime(&p, sa, PFKEYV2_LIFETIME_HARD);    }    /* Export TDB source address */    headers[SADB_EXT_ADDRESS_SRC] = p;    export_address(&p, (struct sockaddr *) &sa->tdb_src);    /* Export TDB destination address */    headers[SADB_EXT_ADDRESS_DST] = p;    export_address(&p, (struct sockaddr *) &sa->tdb_dst);    /* Export TDB proxy address, if present */    if (SA_LEN(&sa->tdb_proxy.sa))    {	headers[SADB_EXT_ADDRESS_PROXY] = p;	export_address(&p, (struct sockaddr *) &sa->tdb_proxy);    }    /* Export source identity, if present */    if (sa->tdb_srcid)    {	headers[SADB_EXT_IDENTITY_SRC] = p;	export_identity(&p, sa, PFKEYV2_IDENTITY_SRC);    }    /* Export destination identity, if present */    if (sa->tdb_dstid)    {	headers[SADB_EXT_IDENTITY_DST] = p;	export_identity(&p, sa, PFKEYV2_IDENTITY_DST);    }    /* Export credentials, if present */    if (sa->tdb_local_cred)    {	headers[SADB_X_EXT_LOCAL_CREDENTIALS] = p;	export_credentials(&p, sa, PFKEYV2_CRED_LOCAL);    }    if (sa->tdb_remote_cred)    {	headers[SADB_X_EXT_REMOTE_CREDENTIALS] = p;	export_credentials(&p, sa, PFKEYV2_CRED_REMOTE);    }    /* Export authentication information, if present */    if (sa->tdb_local_auth)    {	headers[SADB_X_EXT_LOCAL_AUTH] = p;	export_auth(&p, sa, PFKEYV2_AUTH_LOCAL);    }    if (sa->tdb_remote_auth)    {	headers[SADB_X_EXT_REMOTE_AUTH] = p;	export_auth(&p, sa, PFKEYV2_AUTH_REMOTE);    }    /* Export authentication key, if present */    if (sa->tdb_amxkey)    {	headers[SADB_EXT_KEY_AUTH] = p;	export_key(&p, sa, PFKEYV2_AUTHENTICATION_KEY);    }    /* Export encryption key, if present */    if (sa->tdb_emxkey)    {	headers[SADB_EXT_KEY_ENCRYPT] = p;	export_key(&p, sa, PFKEYV2_ENCRYPTION_KEY);    }    rval = 0; ret:    return rval;}