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

Function key_bbcmp

freebsd/netipsec/key.c:4384–4409  ·  view source on GitHub ↗

* compare two buffers with mask. * IN: * addr1: source * addr2: object * bits: Number of bits to compare * OUT: * 1 : equal * 0 : not equal */

Source from the content-addressed store, hash-verified

4382 * 0 : not equal
4383 */
4384static int
4385key_bbcmp(const void *a1, const void *a2, u_int bits)
4386{
4387 const unsigned char *p1 = a1;
4388 const unsigned char *p2 = a2;
4389
4390 /* XXX: This could be considerably faster if we compare a word
4391 * at a time, but it is complicated on LSB Endian machines */
4392
4393 /* Handle null pointers */
4394 if (p1 == NULL || p2 == NULL)
4395 return (p1 == p2);
4396
4397 while (bits >= 8) {
4398 if (*p1++ != *p2++)
4399 return 0;
4400 bits -= 8;
4401 }
4402
4403 if (bits > 0) {
4404 u_int8_t mask = ~((1<<(8-bits))-1);
4405 if ((*p1 & mask) != (*p2 & mask))
4406 return 0;
4407 }
4408 return 1; /* Match! */
4409}
4410
4411static void
4412key_flush_spd(time_t now)

Callers 2

key_cmpspidx_withmaskFunction · 0.85
key_sockaddrcmp_withmaskFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected