Re: rename gettdbbyaddr to gettdbbydst

2015-04-08 Thread Mike Belopuhov
On 8 April 2015 at 12:46, Martin Pieuchot m...@openbsd.org wrote:
 On 08/04/15(Wed) 12:15, Mike Belopuhov wrote:
 OK to rename gettdbbyaddr to gettdbbydst since that's what it does
 and it aligns well with gettdbbysrc?

 Makes sense to me.  This is also coherent to the comments in ip_ipsp.h.

 One comment though, you're moving a splsoftnet() in tdb_delete() but it
 seems that the hash function does not need this protection, or am I
 misunderstanding something?


Just a better place for it to be.  Especially if somebody will turn it into
something else.  There's no functional change.



Re: rename gettdbbyaddr to gettdbbydst

2015-04-08 Thread Martin Pieuchot
On 08/04/15(Wed) 12:15, Mike Belopuhov wrote:
 OK to rename gettdbbyaddr to gettdbbydst since that's what it does
 and it aligns well with gettdbbysrc?

Makes sense to me.  This is also coherent to the comments in ip_ipsp.h.

One comment though, you're moving a splsoftnet() in tdb_delete() but it
seems that the hash function does not need this protection, or am I
misunderstanding something? 

 ---
  sys/netinet/ip_ipsp.c | 47 +--
  sys/netinet/ip_ipsp.h |  4 ++--
  sys/netinet/ip_spd.c  |  6 +++---
  3 files changed, 30 insertions(+), 27 deletions(-)
 
 diff --git sys/netinet/ip_ipsp.c sys/netinet/ip_ipsp.c
 index f6e598f..edeabc8 100644
 --- sys/netinet/ip_ipsp.c
 +++ sys/netinet/ip_ipsp.c
 @@ -118,21 +118,21 @@ struct xformsw xformsw[] = {
 tcp_signature_tdb_zeroize,tcp_signature_tdb_input,
 tcp_signature_tdb_output, }
  #endif /* TCP_SIGNATURE */
  };
  
  struct xformsw *xformswNXFORMSW = xformsw[nitems(xformsw)];
  
  #define  TDB_HASHSIZE_INIT   32
  
  static struct tdb **tdbh = NULL;
 -static struct tdb **tdbaddr = NULL;
 +static struct tdb **tdbdst = NULL;
  static struct tdb **tdbsrc = NULL;
  static u_int tdb_hashmask = TDB_HASHSIZE_INIT - 1;
  static int tdb_count;
  
  /*
   * Our hashing function needs to stir things with a non-zero random 
 multiplier
   * so we cannot be DoS-attacked via choosing of the data to hash.
   */
  int
  tdb_hash(u_int rdomain, u_int32_t spi, union sockaddr_union *dst,
 @@ -393,34 +393,34 @@ ipsp_aux_match(struct tdb *tdb,
   }
  
   return 1;
  }
  
  /*
   * Get an SA given the remote address, the security protocol type, and
   * the desired IDs.
   */
  struct tdb *
 -gettdbbyaddr(u_int rdomain, union sockaddr_union *dst, u_int8_t sproto,
 +gettdbbydst(u_int rdomain, union sockaddr_union *dst, u_int8_t sproto,
  struct ipsec_ref *srcid, struct ipsec_ref *dstid,
  struct ipsec_ref *local_cred, struct sockaddr_encap *filter,
  struct sockaddr_encap *filtermask)
  {
   u_int32_t hashval;
   struct tdb *tdbp;
  
 - if (tdbaddr == NULL)
 + if (tdbdst == NULL)
   return (struct tdb *) NULL;
  
   hashval = tdb_hash(rdomain, 0, dst, sproto);
  
 - for (tdbp = tdbaddr[hashval]; tdbp != NULL; tdbp = tdbp-tdb_anext)
 + for (tdbp = tdbdst[hashval]; tdbp != NULL; tdbp = tdbp-tdb_dnext)
   if ((tdbp-tdb_sproto == sproto) 
   (tdbp-tdb_rdomain == rdomain) 
   ((tdbp-tdb_flags  TDBF_INVALID) == 0) 
   (!memcmp(tdbp-tdb_dst, dst, SA_LEN(dst-sa {
   /* Do IDs and local credentials match ? */
   if (!ipsp_aux_match(tdbp, srcid, dstid,
   local_cred, NULL, filter, filtermask))
   continue;
   break;
   }
 @@ -576,85 +576,85 @@ tdb_soft_firstuse(void *v)
   pfkeyv2_expire(tdb, SADB_EXT_LIFETIME_SOFT);
   tdb-tdb_flags = ~TDBF_SOFT_FIRSTUSE;
  }
  
  /*
   * Caller is responsible for splsoftnet().
   */
  void
  tdb_rehash(void)
  {
 - struct tdb **new_tdbh, **new_tdbaddr, **new_srcaddr, *tdbp, *tdbnp;
 + struct tdb **new_tdbh, **new_tdbdst, **new_srcaddr, *tdbp, *tdbnp;
   u_int i, old_hashmask = tdb_hashmask;
   u_int32_t hashval;
  
   tdb_hashmask = (tdb_hashmask  1) | 1;
  
   new_tdbh = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB,
   M_WAITOK | M_ZERO);
 - new_tdbaddr = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB,
 + new_tdbdst = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB,
   M_WAITOK | M_ZERO);
   new_srcaddr = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB,
   M_WAITOK | M_ZERO);
  
   for (i = 0; i = old_hashmask; i++) {
   for (tdbp = tdbh[i]; tdbp != NULL; tdbp = tdbnp) {
   tdbnp = tdbp-tdb_hnext;
   hashval = tdb_hash(tdbp-tdb_rdomain,
   tdbp-tdb_spi, tdbp-tdb_dst,
   tdbp-tdb_sproto);
   tdbp-tdb_hnext = new_tdbh[hashval];
   new_tdbh[hashval] = tdbp;
   }
  
 - for (tdbp = tdbaddr[i]; tdbp != NULL; tdbp = tdbnp) {
 - tdbnp = tdbp-tdb_anext;
 + for (tdbp = tdbdst[i]; tdbp != NULL; tdbp = tdbnp) {
 + tdbnp = tdbp-tdb_dnext;
   hashval = tdb_hash(tdbp-tdb_rdomain,
   0, tdbp-tdb_dst,
   tdbp-tdb_sproto);
 - tdbp-tdb_anext = new_tdbaddr[hashval];
 - new_tdbaddr[hashval] = tdbp;
 + tdbp-tdb_dnext = new_tdbdst[hashval];
 + new_tdbdst[hashval] = tdbp;
   }
  
   for (tdbp = tdbsrc[i]; tdbp != NULL; tdbp = tdbnp) {
   tdbnp =