Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions include/tscore/ink_inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ union IpEndpoint {
);
/// Assign from an @a addr and @a port.
self &assign(IpAddr const &addr, ///< Address and address family.
in_port_t port = 0 ///< Port (network order).
in_port_t port = 0 ///< Port (network byte order).
);

/// Test for valid IP address.
Expand All @@ -129,11 +129,11 @@ union IpEndpoint {
self &setToLoopback(int family ///< Address family.
);

/// Port in network order.
in_port_t &port();
/// Port in network order.
in_port_t port() const;
/// Port in host order.
/// Port in network byte order.
in_port_t &network_order_port();
/// Port in network byte order.
in_port_t network_order_port() const;
/// Port in host byte order.
in_port_t host_order_port() const;

operator sockaddr *() { return &sa; }
Expand Down Expand Up @@ -436,7 +436,7 @@ ats_ip_addr_size(IpEndpoint const *addr ///< Address object.
}

/** Get a reference to the port in an address.
@note Because this is direct access, the port value is in network order.
@note Because this is direct access, the port value is in network byte order.
@see ats_ip_port_host_order.
@return A reference to the port value in an IPv4 or IPv6 address.
@internal This is primarily for internal use but it might be handy for
Expand Down Expand Up @@ -468,7 +468,7 @@ ats_ip_port_cast(IpEndpoint *ip)

If this is not an IPv4 address a zero valued address is returned.
@note This is direct access to the address so it will be in
network order.
network byte order.

@return A reference to the IPv4 address in @a addr.
*/
Expand All @@ -483,7 +483,7 @@ ats_ip4_addr_cast(sockaddr *addr)

If this is not an IPv4 address a zero valued address is returned.
@note This is direct access to the address so it will be in
network order.
network byte order.

@return A reference to the IPv4 address in @a addr.
*/
Expand All @@ -498,7 +498,7 @@ ats_ip4_addr_cast(sockaddr const *addr)

If this is not an IPv4 address a zero valued address is returned.
@note This is direct access to the address so it will be in
network order.
network byte order.
@note Convenience overload.

@return A reference to the IPv4 address in @a addr.
Expand All @@ -513,7 +513,7 @@ ats_ip4_addr_cast(IpEndpoint *ip)

If this is not an IPv4 address a zero valued address is returned.
@note This is direct access to the address so it will be in
network order.
network byte order.
@note Convenience overload.

@return A reference to the IPv4 address in @a addr.
Expand All @@ -528,7 +528,7 @@ ats_ip4_addr_cast(IpEndpoint const *ip)

If this is not an IPv6 address a zero valued address is returned.
@note This is direct access to the address so it will be in
network order.
network byte order.

@return A reference to the IPv6 address in @a addr.
*/
Expand Down Expand Up @@ -778,8 +778,8 @@ ats_ip_copy(sockaddr *dst, IpEndpoint const *src)
Non-IP < IPv4 < IPv6

- all non-IP addresses are the same ( including @c AF_UNSPEC )
- IPv4 addresses are compared numerically (host order)
- IPv6 addresses are compared byte wise in network order (MSB to LSB)
- IPv4 addresses are compared numerically (host byte order)
- IPv6 addresses are compared byte wise in network byte order (MSB to LSB)

@return
- -1 if @a lhs is less than @a rhs.
Expand Down Expand Up @@ -886,7 +886,7 @@ ats_ip_addr_port_eq(sockaddr const *lhs, sockaddr const *rhs)
//@}

/// Get IP TCP/UDP port.
/// @return The port in host order for an IPv4 or IPv6 address,
/// @return The port in host byte order for an IPv4 or IPv6 address,
/// or zero if neither.
inline in_port_t
ats_ip_port_host_order(sockaddr const *addr ///< Address with port.
Expand All @@ -898,7 +898,7 @@ ats_ip_port_host_order(sockaddr const *addr ///< Address with port.
}

/// Get IP TCP/UDP port.
/// @return The port in host order for an IPv4 or IPv6 address,
/// @return The port in host byte order for an IPv4 or IPv6 address,
/// or zero if neither.
inline in_port_t
ats_ip_port_host_order(IpEndpoint const *ip ///< Address with port.
Expand All @@ -910,7 +910,7 @@ ats_ip_port_host_order(IpEndpoint const *ip ///< Address with port.
}

/** Extract the IPv4 address.
@return Host order IPv4 address.
@return Host byte order IPv4 address.
*/
inline in_addr_t
ats_ip4_addr_host_order(sockaddr const *addr ///< Address object.
Expand All @@ -922,8 +922,8 @@ ats_ip4_addr_host_order(sockaddr const *addr ///< Address object.
/// Write IPv4 data to storage @a dst.
inline sockaddr *
ats_ip4_set(sockaddr_in *dst, ///< Destination storage.
in_addr_t addr, ///< address, IPv4 network order.
in_port_t port = 0 ///< port, network order.
in_addr_t addr, ///< address, IPv4 network byte order.
in_port_t port = 0 ///< port, network byte order.
)
{
ink_zero(*dst);
Expand All @@ -941,8 +941,8 @@ ats_ip4_set(sockaddr_in *dst, ///< Destination storage.
*/
inline sockaddr *
ats_ip4_set(IpEndpoint *dst, ///< Destination storage.
in_addr_t ip4, ///< address, IPv4 network order.
in_port_t port = 0 ///< port, network order.
in_addr_t ip4, ///< address, IPv4 network byte order.
in_port_t port = 0 ///< port, network byte order.
)
{
return ats_ip4_set(&dst->sin, ip4, port);
Expand All @@ -955,8 +955,8 @@ ats_ip4_set(IpEndpoint *dst, ///< Destination storage.
*/
inline sockaddr *
ats_ip4_set(sockaddr *dst, ///< Destination storage.
in_addr_t ip4, ///< address, IPv4 network order.
in_port_t port = 0 ///< port, network order.
in_addr_t ip4, ///< address, IPv4 network byte order.
in_port_t port = 0 ///< port, network byte order.
)
{
return ats_ip4_set(ats_ip4_cast(dst), ip4, port);
Expand All @@ -966,8 +966,8 @@ ats_ip4_set(sockaddr *dst, ///< Destination storage.
*/
inline sockaddr *
ats_ip6_set(sockaddr_in6 *dst, ///< Destination storage.
in6_addr const &addr, ///< address in network order.
in_port_t port = 0 ///< Port, network order.
in6_addr const &addr, ///< address in network byte order.
in_port_t port = 0 ///< Port, network byte order.
)
{
ink_zero(*dst);
Expand All @@ -984,8 +984,8 @@ ats_ip6_set(sockaddr_in6 *dst, ///< Destination storage.
*/
inline sockaddr *
ats_ip6_set(sockaddr *dst, ///< Destination storage.
in6_addr const &addr, ///< address in network order.
in_port_t port = 0 ///< Port, network order.
in6_addr const &addr, ///< address in network byte order.
in_port_t port = 0 ///< Port, network byte order.
)
{
return ats_ip6_set(ats_ip6_cast(dst), addr, port);
Expand All @@ -995,8 +995,8 @@ ats_ip6_set(sockaddr *dst, ///< Destination storage.
*/
inline sockaddr *
ats_ip6_set(IpEndpoint *dst, ///< Destination storage.
in6_addr const &addr, ///< address in network order.
in_port_t port = 0 ///< Port, network order.
in6_addr const &addr, ///< address in network byte order.
in_port_t port = 0 ///< Port, network byte order.
)
{
return ats_ip6_set(&dst->sin6, addr, port);
Expand Down Expand Up @@ -1203,7 +1203,7 @@ struct IpAddr {
return this->assign(&ip.sa);
}
/// Assign from IPv4 raw address.
/// @param ip Network order IPv4 address.
/// @param ip Network byte order IPv4 address.
self &operator=(in_addr_t ip);

/// Assign from IPv6 raw address.
Expand Down Expand Up @@ -1263,7 +1263,7 @@ struct IpAddr {
int cmp(self const &that) const;

/** Return a normalized hash value.
- Ipv4: the address in host order.
- Ipv4: the address in host byte order.
- Ipv6: folded 32 bit of the address.
- Else: 0.
*/
Expand Down Expand Up @@ -1480,7 +1480,7 @@ IpAddr::hash() const
/// @return @s dst.
sockaddr *ats_ip_set(sockaddr *dst, ///< Destination storage.
IpAddr const &addr, ///< source address.
in_port_t port = 0 ///< port, network order.
in_port_t port = 0 ///< port, network byte order.
);

/** Convert @a text to an IP address and write it to @a addr.
Expand Down Expand Up @@ -1512,21 +1512,21 @@ IpEndpoint::assign(sockaddr const *ip)
}

inline in_port_t &
IpEndpoint::port()
IpEndpoint::network_order_port()
{
return ats_ip_port_cast(&sa);
}

inline in_port_t
IpEndpoint::port() const
IpEndpoint::network_order_port() const
{
return ats_ip_port_cast(&sa);
}

inline in_port_t
IpEndpoint::host_order_port() const
{
return ntohs(this->port());
return ntohs(this->network_order_port());
}

inline bool
Expand Down
2 changes: 1 addition & 1 deletion iocore/net/P_NetVConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NetVConnection::get_proxy_protocol_addr(const ProxyProtocolData src_or_dst) cons
{
const IpEndpoint &addr = (src_or_dst == ProxyProtocolData::SRC ? pp_info.src_addr : pp_info.dst_addr);

if ((addr.isValid() && addr.port() != 0) || (ats_is_ip4(&addr) && INADDR_ANY != ats_ip4_addr_cast(&addr)) // IPv4
if ((addr.isValid() && addr.network_order_port() != 0) || (ats_is_ip4(&addr) && INADDR_ANY != ats_ip4_addr_cast(&addr)) // IPv4
|| (ats_is_ip6(&addr) && !IN6_IS_ADDR_UNSPECIFIED(&addr.sin6.sin6_addr))) {
return &addr.sa;
}
Expand Down
4 changes: 2 additions & 2 deletions iocore/net/ProxyProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ proxy_protocol_v1_parse(ProxyProtocol *pp_info, ts::TextView hdr)
static_cast<int>(token.size()), token.data());
return 0;
}
pp_info->src_addr.port() = htons(src_port);
pp_info->src_addr.network_order_port() = htons(src_port);

// Next is the TCP destination port represented as a decimal number in the range of [0..65535] inclusive.
// Final trailer is CR LF so split at CR.
Expand All @@ -205,7 +205,7 @@ proxy_protocol_v1_parse(ProxyProtocol *pp_info, ts::TextView hdr)
static_cast<int>(token.size()), token.data());
return 0;
}
pp_info->dst_addr.port() = htons(dst_port);
pp_info->dst_addr.network_order_port() = htons(dst_port);

pp_info->version = ProxyProtocolVersion::V1;

Expand Down
2 changes: 1 addition & 1 deletion iocore/net/QUICNetProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ QUICNetProcessor::main_accept(Continuation *cont, SOCKET fd, AcceptOptions const
accept_ip.setToAnyAddr(opt.ip_family);
}
ink_assert(0 < opt.local_port && opt.local_port < 65536);
accept_ip.port() = htons(opt.local_port);
accept_ip.network_order_port() = htons(opt.local_port);

na->accept_fn = net_accept;
na->server.fd = fd;
Expand Down
4 changes: 2 additions & 2 deletions iocore/net/SSLCertLookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ SSLCertLookup::find(const IpEndpoint &address) const
}

// If that failed, try the address without the port.
if (address.port()) {
if (address.network_order_port()) {
key.split();
if ((cc = this->ec_storage->lookup(key.get()))) {
return cc;
Expand All @@ -343,7 +343,7 @@ SSLCertLookup::find(const IpEndpoint &address) const
}

// If that failed, try the address without the port.
if (address.port()) {
if (address.network_order_port()) {
key.split();
return this->ssl_storage->lookup(key.get());
}
Expand Down
6 changes: 3 additions & 3 deletions iocore/net/UnixConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ Connection::open(NetVCOptions const &opt)
// No local address specified, so use family option if possible.
family = ats_is_ip(opt.ip_family) ? opt.ip_family : AF_INET;
local_addr.setToAnyAddr(family);
is_any_address = true;
local_addr.port() = htons(opt.local_port);
is_any_address = true;
local_addr.network_order_port() = htons(opt.local_port);
}

res = socketManager.socket(family, sock_type, 0);
Expand Down Expand Up @@ -196,7 +196,7 @@ Connection::open(NetVCOptions const &opt)
// apply dynamic options
apply_options(opt);

if (local_addr.port() || !is_any_address) {
if (local_addr.network_order_port() || !is_any_address) {
if (-1 == socketManager.ink_bind(fd, &local_addr.sa, ats_ip_size(&local_addr.sa))) {
return -errno;
}
Expand Down
5 changes: 3 additions & 2 deletions iocore/net/UnixNetAccept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,14 @@ NetAccept::do_listen(bool non_blocking)

if (server.fd != NO_FD) {
if ((res = server.setup_fd_for_listen(non_blocking, opt))) {
Warning("unable to listen on main accept port %d: errno = %d, %s", ntohs(server.accept_addr.port()), errno, strerror(errno));
Warning("unable to listen on main accept port %d: errno = %d, %s", server.accept_addr.host_order_port(), errno,
strerror(errno));
goto Lretry;
}
} else {
Lretry:
if ((res = server.listen(non_blocking, opt))) {
Warning("unable to listen on port %d: %d %d, %s", ntohs(server.accept_addr.port()), res, errno, strerror(errno));
Warning("unable to listen on port %d: %d %d, %s", server.accept_addr.host_order_port(), res, errno, strerror(errno));
}
}

Expand Down
2 changes: 1 addition & 1 deletion iocore/net/UnixNetProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions cons
accept_ip.setToAnyAddr(opt.ip_family);
}
ink_assert(0 < opt.local_port && opt.local_port < 65536);
accept_ip.port() = htons(opt.local_port);
accept_ip.network_order_port() = htons(opt.local_port);

na->accept_fn = net_accept; // All callers used this.
na->server.fd = fd;
Expand Down
6 changes: 3 additions & 3 deletions iocore/net/UnixUDPNet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ UDPNetProcessor::CreateUDPSocket(int *resfd, sockaddr const *remote_addr, Action
// No local address specified, so use family option if possible.
int family = ats_is_ip(opt.ip_family) ? opt.ip_family : AF_INET;
local_addr.setToAnyAddr(family);
is_any_address = true;
local_addr.port() = htons(opt.local_port);
is_any_address = true;
local_addr.network_order_port() = htons(opt.local_port);
}

*resfd = -1;
Expand Down Expand Up @@ -698,7 +698,7 @@ UDPNetProcessor::CreateUDPSocket(int *resfd, sockaddr const *remote_addr, Action
}
}

if (local_addr.port() || !is_any_address) {
if (local_addr.network_order_port() || !is_any_address) {
if (-1 == socketManager.ink_bind(fd, &local_addr.sa, ats_ip_size(&local_addr.sa))) {
char buff[INET6_ADDRPORTSTRLEN];
Debug("udpnet", "ink bind failed on %s", ats_ip_nptop(local_addr, buff, sizeof(buff)));
Expand Down
4 changes: 2 additions & 2 deletions iocore/net/quic/QUICTypes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ QUICPreferredAddress::store(uint8_t *buf, uint16_t &len) const
QUICFiveTuple::QUICFiveTuple(IpEndpoint src, IpEndpoint dst, int protocol) : _source(src), _destination(dst), _protocol(protocol)
{
// FIXME Generate a hash code
this->_hash_code = src.port() + dst.port() + protocol;
this->_hash_code = src.network_order_port() + dst.network_order_port() + protocol;
}
void
QUICFiveTuple::update(IpEndpoint src, IpEndpoint dst, int protocol)
Expand All @@ -580,7 +580,7 @@ QUICFiveTuple::update(IpEndpoint src, IpEndpoint dst, int protocol)
this->_protocol = protocol;

// FIXME Generate a hash code
this->_hash_code = src.port() + dst.port() + protocol;
this->_hash_code = src.network_order_port() + dst.network_order_port() + protocol;
}

IpEndpoint
Expand Down
8 changes: 5 additions & 3 deletions iocore/net/quic/QUICTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,13 @@ class QUICPath
inline bool
operator==(const QUICPath &x) const
{
if ((this->_local_ep.port() != 0 && x._local_ep.port() != 0) && this->_local_ep.port() != x._local_ep.port()) {
if ((this->_local_ep.network_order_port() != 0 && x._local_ep.network_order_port() != 0) &&
this->_local_ep.network_order_port() != x._local_ep.network_order_port()) {
return false;
}

if ((this->_remote_ep.port() != 0 && x._remote_ep.port() != 0) && this->_remote_ep.port() != x._remote_ep.port()) {
if ((this->_remote_ep.network_order_port() != 0 && x._remote_ep.network_order_port() != 0) &&
this->_remote_ep.network_order_port() != x._remote_ep.network_order_port()) {
return false;
}

Expand All @@ -498,7 +500,7 @@ class QUICPathHasher
std::size_t
operator()(const QUICPath &k) const
{
return k.remote_ep().port();
return k.remote_ep().network_order_port();
}
};

Expand Down
Loading