blob: 3bcc7dff782f5c0b4e9b210c6b08b45a5caa1cce [file] [log] [blame]
Bob Beck8e7025e2023-09-05 17:05:26 -06001// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BSSL_PKI_IP_UTIL_H_
6#define BSSL_PKI_IP_UTIL_H_
7
Bob Beck3cd30cc2023-11-22 16:59:00 -07008#include <openssl/base.h>
Bob Beck8e7025e2023-09-05 17:05:26 -06009
10#include "input.h"
11
12namespace bssl {
13
14inline constexpr size_t kIPv4AddressSize = 4;
15inline constexpr size_t kIPv6AddressSize = 16;
16
Bob Beck3aecf1d2023-09-08 11:56:02 -060017// Returns whether `mask` is a valid netmask. I.e., whether it is the length of
18// an IPv4 or IPv6 address, and is some number of ones, followed by some number
19// of zeros.
Bob Beck8e7025e2023-09-05 17:05:26 -060020OPENSSL_EXPORT bool IsValidNetmask(der::Input mask);
21
22// Returns whether `addr1` and `addr2` are equal under the netmask `mask`.
23OPENSSL_EXPORT bool IPAddressMatchesWithNetmask(der::Input addr1,
Bob Beck5c7a2a02023-11-20 17:28:21 -070024 der::Input addr2,
25 der::Input mask);
Bob Beck8e7025e2023-09-05 17:05:26 -060026
Bob Beck5c7a2a02023-11-20 17:28:21 -070027} // namespace bssl
Bob Beck8e7025e2023-09-05 17:05:26 -060028
29#endif // BSSL_PKI_IP_UTIL_H_