* Find TCP-MD5 SA with corresponding secasindex. * If not found, return NULL and fill SPI with usable value if needed. */
| 5062 | * If not found, return NULL and fill SPI with usable value if needed. |
| 5063 | */ |
| 5064 | static struct secasvar * |
| 5065 | key_getsav_tcpmd5(struct secasindex *saidx, uint32_t *spi) |
| 5066 | { |
| 5067 | SAHTREE_RLOCK_TRACKER; |
| 5068 | struct secashead *sah; |
| 5069 | struct secasvar *sav; |
| 5070 | |
| 5071 | IPSEC_ASSERT(saidx->proto == IPPROTO_TCP, ("wrong proto")); |
| 5072 | SAHTREE_RLOCK(); |
| 5073 | LIST_FOREACH(sah, SAHADDRHASH_HASH(saidx), addrhash) { |
| 5074 | if (sah->saidx.proto != IPPROTO_TCP) |
| 5075 | continue; |
| 5076 | if (!key_sockaddrcmp(&saidx->dst.sa, &sah->saidx.dst.sa, 0) && |
| 5077 | !key_sockaddrcmp(&saidx->src.sa, &sah->saidx.src.sa, 0)) |
| 5078 | break; |
| 5079 | } |
| 5080 | if (sah != NULL) { |
| 5081 | if (V_key_preferred_oldsa) |
| 5082 | sav = TAILQ_LAST(&sah->savtree_alive, secasvar_queue); |
| 5083 | else |
| 5084 | sav = TAILQ_FIRST(&sah->savtree_alive); |
| 5085 | if (sav != NULL) { |
| 5086 | SAV_ADDREF(sav); |
| 5087 | SAHTREE_RUNLOCK(); |
| 5088 | return (sav); |
| 5089 | } |
| 5090 | } |
| 5091 | if (spi == NULL) { |
| 5092 | /* No SPI required */ |
| 5093 | SAHTREE_RUNLOCK(); |
| 5094 | return (NULL); |
| 5095 | } |
| 5096 | /* Check that SPI is unique */ |
| 5097 | LIST_FOREACH(sav, SAVHASH_HASH(*spi), spihash) { |
| 5098 | if (sav->spi == *spi) |
| 5099 | break; |
| 5100 | } |
| 5101 | if (sav == NULL) { |
| 5102 | SAHTREE_RUNLOCK(); |
| 5103 | /* SPI is already unique */ |
| 5104 | return (NULL); |
| 5105 | } |
| 5106 | SAHTREE_RUNLOCK(); |
| 5107 | /* XXX: not optimal */ |
| 5108 | *spi = key_do_getnewspi(NULL, saidx); |
| 5109 | return (NULL); |
| 5110 | } |
| 5111 | |
| 5112 | static int |
| 5113 | key_updateaddresses(struct socket *so, struct mbuf *m, |
no test coverage detected