Skip to content

Commit

Permalink
net: ipv6: Add APIs to check ipv6 address is site local and global
Browse files Browse the repository at this point in the history
Add APIs to check the IPv6 address is site local or is global.

(cherry picked from commit 68bea80)

Original-Signed-off-by: Sandip Dalvi <[email protected]>
GitOrigin-RevId: 68bea80
Change-Id: I58432c14b13d50fd878d9a21d1004c459cafb631
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5227907
Reviewed-by: Tristan Honscheid <[email protected]>
Tested-by: ChromeOS Prod (Robot) <[email protected]>
Tested-by: Tristan Honscheid <[email protected]>
Commit-Queue: Tristan Honscheid <[email protected]>
  • Loading branch information
sandip-dalvi authored and Chromeos LUCI committed Feb 3, 2024
1 parent d8faf7c commit c176bf8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/zephyr/net/net_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,19 @@ static inline bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFE80);
}

/**
* @brief Check if the given IPv6 address is a site local address.
*
* @param addr A valid pointer on an IPv6 address
*
* @return True if it is, false otherwise.
*/
static inline bool net_ipv6_is_sl_addr(const struct in6_addr *addr)
{
return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFEC0);
}


/**
* @brief Check if the given IPv6 address is a unique local address.
*
Expand All @@ -853,6 +866,18 @@ static inline bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
return addr->s6_addr[0] == 0xFD;
}

/**
* @brief Check if the given IPv6 address is a global address.
*
* @param addr A valid pointer on an IPv6 address
*
* @return True if it is, false otherwise.
*/
static inline bool net_ipv6_is_global_addr(const struct in6_addr *addr)
{
return (addr->s6_addr[0] & 0xE0) == 0x20;
}

/**
* @brief Return pointer to any (all bits zeros) IPv6 address.
*
Expand Down

0 comments on commit c176bf8

Please sign in to comment.