Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SRTO_IPV6ONLY option #608

Merged
merged 15 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ void CUDTUnited::updateMux(
#endif
m.m_pChannel->setSndBufSize(s->m_pUDT->m_iUDPSndBufSize);
m.m_pChannel->setRcvBufSize(s->m_pUDT->m_iUDPRcvBufSize);
m.m_pChannel->setIpV6Only(s->m_pUDT->m_bIpV6Only);

try
{
Expand Down
12 changes: 11 additions & 1 deletion srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ m_iIpTTL(-1), /* IPv4 TTL or IPv6 HOPs [1..255] (-1:undefined) */
m_iIpToS(-1), /* IPv4 Type of Service or IPv6 Traffic Class [0x00..0xff] (-1:undefined) */
#endif
m_iSndBufSize(65536),
m_iRcvBufSize(65536)
m_iRcvBufSize(65536),
m_iIpV6Only(-1)
{
}

Expand All @@ -115,6 +116,7 @@ m_iIpToS(-1),
#endif
m_iSndBufSize(65536),
m_iRcvBufSize(65536),
m_iIpV6Only(-1),
m_BindAddr(version)
{
m_iSockAddrSize = (AF_INET == m_iIPversion) ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
Expand All @@ -136,6 +138,9 @@ void CChannel::open(const sockaddr* addr)
#endif
throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR);

if ((m_iIpV6Only != -1) && (m_iIPversion == AF_INET6)) // (not an error if it fails)
::setsockopt(m_iSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)(&m_iIpV6Only), sizeof(m_iIpV6Only));

if (NULL != addr)
{
socklen_t namelen = m_iSockAddrSize;
Expand Down Expand Up @@ -287,6 +292,11 @@ void CChannel::setRcvBufSize(int size)
m_iRcvBufSize = size;
}

void CChannel::setIpV6Only(bool ipV6Only)
{
m_iIpV6Only = ipV6Only;
}

#ifdef SRT_ENABLE_IPOPTS
int CChannel::getIpTTL() const
{
Expand Down
6 changes: 6 additions & 0 deletions srtcore/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class CChannel

void setRcvBufSize(int size);

/// Set the IPV6ONLY option.
/// @param [in] IPV6ONLY value.

void setIpV6Only(bool ipV6Only);

/// Query the socket address that the channel is using.
/// @param [out] addr pointer to store the returned socket address.

Expand Down Expand Up @@ -174,6 +179,7 @@ class CChannel
#endif
int m_iSndBufSize; // UDP sending buffer size
int m_iRcvBufSize; // UDP receiving buffer size
int m_iIpV6Only; // IPV6_V6ONLY option (-1 if not set)
sockaddr_any m_BindAddr;
};

Expand Down
14 changes: 14 additions & 0 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ CUDT::CUDT()
m_bTLPktDrop = true; //Too-late Packet Drop
m_bMessageAPI = true;
m_zOPT_ExpPayloadSize = SRT_LIVE_DEF_PLSIZE;
m_bIpV6Only = true;
//Runtime
m_bRcvNakReport = true; //Receiver's Periodic NAK Reports
m_llInputBW = 0; // Application provided input bandwidth (internal input rate sampling == 0)
Expand Down Expand Up @@ -326,6 +327,7 @@ CUDT::CUDT(const CUDT& ancestor)
m_zOPT_ExpPayloadSize = ancestor.m_zOPT_ExpPayloadSize;
m_bTLPktDrop = ancestor.m_bTLPktDrop;
m_bMessageAPI = ancestor.m_bMessageAPI;
m_bIpV6Only = ancestor.m_bIpV6Only;
//Runtime
m_bRcvNakReport = ancestor.m_bRcvNakReport;

Expand Down Expand Up @@ -844,6 +846,13 @@ void CUDT::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)
m_bOPT_StrictEncryption = bool_int_value(optval, optlen);
break;

case SRTO_IPV6ONLY:
if (m_bConnected)
throw CUDTException(MJ_NOTSUP, MN_ISCONNECTED, 0);

m_bIpV6Only = bool_int_value(optval, optlen);
break;

thomasjammet marked this conversation as resolved.
Show resolved Hide resolved
default:
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}
Expand Down Expand Up @@ -1116,6 +1125,11 @@ void CUDT::getOpt(SRT_SOCKOPT optName, void* optval, int& optlen)
*(int32_t*)optval = m_bOPT_StrictEncryption;
break;

case SRTO_IPV6ONLY:
optlen = sizeof(int32_t);
*(int32_t*)optval = m_bIpV6Only;
break;

thomasjammet marked this conversation as resolved.
Show resolved Hide resolved
default:
throw CUDTException(MJ_NOTSUP, MN_NONE, 0);
}
Expand Down
1 change: 1 addition & 0 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ class CUDT
int64_t m_llInputBW; // Input stream rate (bytes/sec)
int m_iOverheadBW; // Percent above input stream rate (applies if m_llMaxBW == 0)
bool m_bRcvNakReport; // Enable Receiver Periodic NAK Reports
bool m_bIpV6Only; // IPV6_V6ONLY option
private:
UniquePtr<CCryptoControl> m_pCryptoControl; // congestion control SRT class (small data extension)
CCache<CInfoBlock>* m_pCache; // network information cache
Expand Down
3 changes: 2 additions & 1 deletion srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ typedef enum SRT_SOCKOPT {
SRTO_KMREFRESHRATE, // After sending how many packets the encryption key should be flipped to the new key
SRTO_KMPREANNOUNCE, // How many packets before key flip the new key is annnounced and after key flip the old one decommissioned
SRTO_STRICTENC, // Connection to be rejected or quickly broken when one side encryption set or bad password
SRTO_IPV6ONLY, // IPV6_V6ONLY mode
} SRT_SOCKOPT;

// DEPRECATED OPTIONS:
Expand Down Expand Up @@ -501,7 +502,7 @@ inline bool operator&(int flags, SRT_EPOLL_OPT eflg)
// Using an enum prevents treating int automatically as enum,
// requires explicit enum to be passed here, and minimizes the
// risk that the right side value will contain multiple flags.
return flags & int(eflg);
return (flags & int(eflg)) != 0;
}
#endif

Expand Down