Skip to content

Commit

Permalink
Merge pull request #17312 from donaldsharp/remove_in6addr_cmp
Browse files Browse the repository at this point in the history
Remove in6addr cmp
  • Loading branch information
ton31337 authored Nov 1, 2024
2 parents 4411ee9 + ff9781e commit a69f661
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
26 changes: 4 additions & 22 deletions lib/sockunion.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ int sockunion_same(const union sockunion *su1, const union sockunion *su2)
sizeof(struct in_addr));
break;
case AF_INET6:
ret = memcmp(&su1->sin6.sin6_addr, &su2->sin6.sin6_addr,
sizeof(struct in6_addr));
ret = IPV6_ADDR_CMP(&su1->sin6.sin6_addr, &su2->sin6.sin6_addr);
if ((ret == 0) && IN6_IS_ADDR_LINKLOCAL(&su1->sin6.sin6_addr)) {
/* compare interface indices */
if (su1->sin6.sin6_scope_id && su2->sin6.sin6_scope_id)
Expand Down Expand Up @@ -588,23 +587,6 @@ static void __attribute__((unused)) sockunion_print(const union sockunion *su)
}
}

int in6addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
{
unsigned int i;
const uint8_t *p1, *p2;

p1 = (const uint8_t *)addr1;
p2 = (const uint8_t *)addr2;

for (i = 0; i < sizeof(struct in6_addr); i++) {
if (p1[i] > p2[i])
return 1;
else if (p1[i] < p2[i])
return -1;
}
return 0;
}

int sockunion_cmp(const union sockunion *su1, const union sockunion *su2)
{
if (su1->sa.sa_family > su2->sa.sa_family)
Expand All @@ -621,7 +603,8 @@ int sockunion_cmp(const union sockunion *su1, const union sockunion *su2)
return -1;
}
if (su1->sa.sa_family == AF_INET6)
return in6addr_cmp(&su1->sin6.sin6_addr, &su2->sin6.sin6_addr);
return IPV6_ADDR_CMP(&su1->sin6.sin6_addr, &su2->sin6.sin6_addr);

return 0;
}

Expand Down Expand Up @@ -727,8 +710,7 @@ int sockunion_is_null(const union sockunion *su)
case AF_INET:
return (su->sin.sin_addr.s_addr == 0);
case AF_INET6:
return !memcmp(su->sin6.sin6_addr.s6_addr, null_s6_addr,
sizeof(null_s6_addr));
return !IPV6_ADDR_CMP(su->sin6.sin6_addr.s6_addr, null_s6_addr);
default:
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion lib/sockunion.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ enum connect_result { connect_error, connect_success, connect_in_progress };
/* Prototypes. */
extern int str2sockunion(const char *, union sockunion *);
extern const char *sockunion2str(const union sockunion *, char *, size_t);
int in6addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2);
extern int sockunion_cmp(const union sockunion *, const union sockunion *);
extern int sockunion_same(const union sockunion *, const union sockunion *);
extern unsigned int sockunion_hash(const union sockunion *);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_frrlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void test_encode_decode(void)

lua_pushin6addr(L, &in6addr_a);
lua_decode_in6addr(L, -1, &in6addr_a);
assert(in6addr_cmp(&in6addr_a, &in6addr_b) == 0);
assert(memcmp(&in6addr_a, &in6addr_b, sizeof(struct in6_addr)) == 0);
assert(lua_gettop(L) == 0);

union sockunion su_a, su_b;
Expand Down

0 comments on commit a69f661

Please sign in to comment.