Deep-copy a policy in PCB. */
| 185 | |
| 186 | /* Deep-copy a policy in PCB. */ |
| 187 | static struct secpolicy * |
| 188 | ipsec_deepcopy_pcbpolicy(struct secpolicy *src) |
| 189 | { |
| 190 | struct secpolicy *dst; |
| 191 | int i; |
| 192 | |
| 193 | if (src == NULL) |
| 194 | return (NULL); |
| 195 | |
| 196 | IPSEC_ASSERT(src->state == IPSEC_SPSTATE_PCB, ("SP isn't PCB")); |
| 197 | |
| 198 | dst = key_newsp(); |
| 199 | if (dst == NULL) |
| 200 | return (NULL); |
| 201 | |
| 202 | /* spidx is not copied here */ |
| 203 | dst->policy = src->policy; |
| 204 | dst->state = src->state; |
| 205 | dst->priority = src->priority; |
| 206 | /* Do not touch the refcnt field. */ |
| 207 | |
| 208 | /* Copy IPsec request chain. */ |
| 209 | for (i = 0; i < src->tcount; i++) { |
| 210 | dst->req[i] = ipsec_newisr(); |
| 211 | if (dst->req[i] == NULL) { |
| 212 | key_freesp(&dst); |
| 213 | return (NULL); |
| 214 | } |
| 215 | bcopy(src->req[i], dst->req[i], sizeof(struct ipsecrequest)); |
| 216 | dst->tcount++; |
| 217 | } |
| 218 | KEYDBG(IPSEC_DUMP, |
| 219 | printf("%s: copied SP(%p) -> SP(%p)\n", __func__, src, dst); |
| 220 | kdebug_secpolicy(dst)); |
| 221 | return (dst); |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Copy IPsec policy from old INPCB into new. |
no test coverage detected