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

Contrib - Improving NAT/PAT Bypass + DSCP on Control Session #100

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions owamp/owamp/conf/twampd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ verbose
# (defaults to daemon)
facility local5

# The minimum severity of log messages to report to syslog. Useful for remote
# syslog servers especially since can reduce log traffic on wire. Valid values:
# FATAL - Just report error messages
# WARN - In addition to FATAL messages, print non-fatal warnings
# INFO - **DEFAULT** In addition to to everything in WARN, print some potentially helpful non-error messages
# DEBUG - Print everything in INFO, and lots of other output that may or may not be useful
# ALL - Print any error message regardless of level
# NONE - Don't send any messages to syslog
#loglevel INFO

# include src file:line in log messages
# keep this on, and help us with more specific bug reports!
# (defaults to !loglocation)
Expand Down
1 change: 1 addition & 0 deletions owamp/owamp/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@ AC_SUBST(ac_aux_dir)
AC_OUTPUT([Makefile owamp/Makefile owampd/Makefile owping/Makefile powstream/Makefile conf/Makefile test/Makefile doc/Makefile selinux/Makefile],
[test -z "$CONFIG_HEADERS" || echo timestamp > owamp/stamp-h.in])


2 changes: 1 addition & 1 deletion owamp/owamp/owamp/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2904,7 +2904,7 @@ OWPWriteDataHeader(
(struct sockaddr*)&hdr->addr_sender,
(struct sockaddr*)&hdr->addr_receiver,
hdr->twoway?True:hdr->conf_sender,hdr->conf_receiver,False,
False,hdr->sid,&hdr->test_spec) != 0) || !len){
False,False,hdr->sid,&hdr->test_spec) != 0) || !len){
return False;
}
ver = htonl((hdr->twoway?_OWP_VERSION_TWOWAY:0)|3);
Expand Down
109 changes: 92 additions & 17 deletions owamp/owamp/owamp/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ TryAddr(
struct addrinfo *ai,
const char *local_addr,
const char *interface,
I2Addr server_addr
I2Addr server_addr,
uint32_t dscp_ctrl /* DSCP Value */
)
{
OWPErrSeverity addr_ok=OWPErrOK;
Expand All @@ -180,7 +181,73 @@ TryAddr(
fd = socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol);
if(fd < 0)
return 1;


if(dscp_ctrl != 0)
/* SET DSCP Value On CTRL Session */
{
/* For now, just verify dscp_ctrl set to valid value
* for DSCP mode:
* Only 6 bits can be set for it to be valid
* (bits 2-7 of the high-order byte)
*/
int optname = IP_TOS;
int optlevel = IP_TOS;
int sopt;
if(dscp_ctrl & ~0x3F000000){
OWPError(cntrl->ctx,OWPErrFATAL,OWPErrUNSUPPORTED,
"Unsupported DSCP CTRL requested");
/*
* This was a valid request, this implementation just doesn't
* support it.
*/
goto cleanup;
}
/*
* TODO: When I find a kernel that actually has IPV6_TCLASS
* make sure it works. (This looks like the RFC 3542 way...)
*/
switch(ai->ai_family){
case AF_INET:
optlevel = IPPROTO_IP;
optname = IP_TOS;
break;
#ifdef AF_INET6
case AF_INET6:
optlevel = IPPROTO_IPV6;
/*
* Look for RFC 3542 sockopts - have no systems with them, but look
* for them anyway...
*/
#ifdef IPV6_TCLASS
optname = IPV6_TCLASS;
#else
optname = IP_TOS;
#endif
break;
#endif
default:
/*NOTREACHED*/
break;
}

/* Copy high-order byte (minus first two bits) */
sopt = (uint8_t)(dscp_ctrl >> 24);
sopt &= 0x3F; /* this should be a no-op until PHB... */

/* shift for setting TOS */
sopt <<= 2;
if(setsockopt(fd,optlevel,optname,
(void*)&sopt,sizeof(sopt)) < 0){
OWPError(cntrl->ctx,OWPErrFATAL,OWPErrUNKNOWN,
"setsockopt(%s,%s=%d): %M",
((optlevel==IPPROTO_IP)?
"IPPROTO_IP":"IPPROTO_IPV6"),
((optname==IP_TOS)?"IP_TOS":"IPV6_TCLASS"),
sopt);
goto cleanup;
}
}

if(interface){
if(!OWPSocketInterfaceBind(cntrl,fd,interface))
goto cleanup;
Expand Down Expand Up @@ -261,6 +328,7 @@ _OWPClientConnect(
const char *local_addr,
const char *interface,
I2Addr server_addr,
uint32_t dscp_ctrl, /* DSCP Value */
OWPErrSeverity *err_ret
)
{
Expand Down Expand Up @@ -314,7 +382,7 @@ _OWPClientConnect(

if(ai->ai_family != AF_INET6) continue;

if( (rc = TryAddr(cntrl,ai,local_addr,interface,server_addr)) == 0)
if( (rc = TryAddr(cntrl,ai,local_addr,interface,server_addr,dscp_ctrl)) == 0)
return 0;
if(rc < 0)
goto error;
Expand All @@ -329,7 +397,7 @@ _OWPClientConnect(

if(ai->ai_family != AF_INET) continue;

if( (rc = TryAddr(cntrl,ai,local_addr,interface,server_addr)) == 0)
if( (rc = TryAddr(cntrl,ai,local_addr,interface,server_addr,dscp_ctrl)) == 0)
return 0;
if(rc < 0)
goto error;
Expand Down Expand Up @@ -390,6 +458,7 @@ OWPControlOpenCommon(
const char *interface, /* interface to bind to or null */
I2Addr server_addr, /* server addr */
uint32_t mode_req_mask, /* requested modes */
uint32_t dscp_ctrl, /* DSCP Value */
OWPUserID userid, /* userid or NULL */
OWPNum64 *uptime_ret, /* server uptime - ret */
OWPErrSeverity *err_ret, /* err - return */
Expand Down Expand Up @@ -439,7 +508,7 @@ OWPControlOpenCommon(
* Connect to the server.
* Address policy check happens in here.
*/
if(_OWPClientConnect(cntrl,local_addr,interface,server_addr,err_ret) != 0)
if(_OWPClientConnect(cntrl,local_addr,interface,server_addr,dscp_ctrl,err_ret) != 0)
goto error;

if(!cntrl->local_addr){
Expand Down Expand Up @@ -691,12 +760,13 @@ OWPControlOpen(
const char *local_addr, /* local addr or null */
I2Addr server_addr, /* server addr */
uint32_t mode_req_mask, /* requested modes */
uint32_t dscp_ctrl, /* DSCP Value */
OWPUserID userid, /* userid or NULL */
OWPNum64 *uptime_ret, /* server uptime - ret */
OWPErrSeverity *err_ret /* err - return */
)
{
return OWPControlOpenCommon(ctx,local_addr,NULL,server_addr,mode_req_mask,
return OWPControlOpenCommon(ctx,local_addr,NULL,server_addr,mode_req_mask,dscp_ctrl,
userid,uptime_ret,err_ret,False);
}

Expand All @@ -718,13 +788,14 @@ OWPControlOpenInterface(
const char *interface, /* interface to bind to or null */
I2Addr server_addr, /* server addr */
uint32_t mode_req_mask, /* requested modes */
uint32_t dscp_ctrl, /* DSCP Value */
OWPUserID userid, /* userid or NULL */
OWPNum64 *uptime_ret, /* server uptime - ret */
OWPErrSeverity *err_ret /* err - return */
)
{
return OWPControlOpenCommon(ctx,local_addr,interface,server_addr,
mode_req_mask,userid,uptime_ret,err_ret,False);
return OWPControlOpenCommon(ctx,local_addr,interface,server_addr,mode_req_mask,dscp_ctrl,
userid,uptime_ret,err_ret,False);
}

/*
Expand All @@ -747,12 +818,13 @@ TWPControlOpen(
const char *local_addr, /* local addr or null */
I2Addr server_addr, /* server addr */
uint32_t mode_req_mask, /* requested modes */
uint32_t dscp_ctrl, /* DSCP Value */
OWPUserID userid, /* userid or NULL */
OWPNum64 *uptime_ret, /* server uptime - ret */
OWPErrSeverity *err_ret /* err - return */
)
{
return OWPControlOpenCommon(ctx,local_addr,NULL,server_addr,mode_req_mask,
return OWPControlOpenCommon(ctx,local_addr,NULL,server_addr,mode_req_mask,dscp_ctrl,
userid,uptime_ret,err_ret,True);
}

Expand All @@ -774,13 +846,14 @@ TWPControlOpenInterface(
const char *interface, /* interface to bind to or null */
I2Addr server_addr, /* server addr */
uint32_t mode_req_mask, /* requested modes */
uint32_t dscp_ctrl, /* DSCP Value */
OWPUserID userid, /* userid or NULL */
OWPNum64 *uptime_ret, /* server uptime - ret */
OWPErrSeverity *err_ret /* err - return */
)
{
return OWPControlOpenCommon(ctx,local_addr,interface,server_addr,
mode_req_mask,userid,uptime_ret,err_ret,True);
return OWPControlOpenCommon(ctx,local_addr,interface,server_addr,mode_req_mask,dscp_ctrl,
userid,uptime_ret,err_ret,True);
}

/*
Expand All @@ -807,7 +880,8 @@ _OWPClientRequestTestReadResponse(
OWPBoolean server_conf_sender,
I2Addr receiver,
OWPBoolean server_conf_receiver,
OWPBoolean zero_addr,
OWPBoolean zero_sender_addr,
OWPBoolean zero_receiver_addr,
OWPTestSpec *test_spec,
OWPSID sid, /* ret iff cntrl->twoway || conf_receiver else set */
OWPErrSeverity *err_ret
Expand Down Expand Up @@ -836,7 +910,7 @@ _OWPClientRequestTestReadResponse(
I2AddrSAddr(sender,NULL),
I2AddrSAddr(receiver,NULL),
server_conf_sender, server_conf_receiver,
zero_addr,
zero_sender_addr, zero_receiver_addr,
cntrl->twoway ? NULL : sid, test_spec)) < OWPErrOK){
*err_ret = (OWPErrSeverity)rc;
return 1;
Expand All @@ -853,7 +927,7 @@ _OWPClientRequestTestReadResponse(

/*
* Figure out if the server will be returning Port field.
* If so - set set_addr to the sockaddr that needs to be set.
* If so - set set_addr to the sockaddr that needs to be set.
*/
if(server_conf_sender && !server_conf_receiver){
if( !I2AddrSetPort(sender,port_ret)){
Expand Down Expand Up @@ -909,7 +983,8 @@ OWPSessionRequest(
OWPBoolean server_conf_sender,
I2Addr receiver,
OWPBoolean server_conf_receiver,
OWPBoolean zero_addr,
OWPBoolean zero_sender_addr,
OWPBoolean zero_receiver_addr,
OWPTestSpec *test_spec,
FILE *fp,
OWPSID sid_ret,
Expand Down Expand Up @@ -1125,7 +1200,7 @@ OWPSessionRequest(
!cntrl->twoway && server_conf_sender,
receiver,
!cntrl->twoway && server_conf_receiver,
zero_addr,
zero_sender_addr, zero_receiver_addr,
test_spec,tsession->sid,err_ret)) != 0){
goto error;
}
Expand Down Expand Up @@ -1208,7 +1283,7 @@ OWPSessionRequest(
if((rc = _OWPClientRequestTestReadResponse(cntrl,retn_on_intr,
sender,server_conf_sender,
receiver,server_conf_receiver,
zero_addr,
zero_sender_addr,zero_receiver_addr,
test_spec,tsession->sid,err_ret)) != 0){
goto error;
}
Expand Down
44 changes: 31 additions & 13 deletions owamp/owamp/owamp/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -2393,12 +2393,21 @@ run_receiver(
/*
* Verify peer before looking at packet.
*/
if(I2SockAddrEqual(rsaddr,rsaddrlen,
(struct sockaddr*)&peer_addr,
peer_addr_len,I2SADDR_ALL) <= 0){
goto again;
}

// If Remote PAT-T set, do not check Sending Port from Sender Node
if((OWPBoolean)OWPContextConfigGetV(ep->cntrl->ctx,OWPPATTRemote))
{
if(I2SockAddrEqual(rsaddr,rsaddrlen,
(struct sockaddr*)&peer_addr,
peer_addr_len,I2SADDR_ADDR) <= 0){
goto again;
}
}
else if(I2SockAddrEqual(rsaddr,rsaddrlen,
(struct sockaddr*)&peer_addr,
peer_addr_len,I2SADDR_ALL) <= 0){
goto again;
}

/*
* Decrypt the packet if needed.
*/
Expand Down Expand Up @@ -2617,7 +2626,7 @@ run_reflector(
uint8_t ttl;
size_t snd_payload_len;
uint32_t testtimeout;

if( !(lsaddr = I2AddrSAddr(ep->tsession->sender,&lsaddrlen))){
exit(OWP_CNTRL_FAILURE);
}
Expand Down Expand Up @@ -2825,12 +2834,21 @@ run_reflector(

/*
* Verify peer before looking at packet.
*/
if(I2SockAddrEqual(rsaddr,rsaddrlen,
(struct sockaddr*)&peer_addr,
peer_addr_len,I2SADDR_ALL) <= 0){
goto again;
}
*/
// If Remote PAT-T set, do not check Sending Port from Sender Node
if((OWPBoolean)OWPContextConfigGetV(ep->cntrl->ctx,OWPPATTRemote))
{
if(I2SockAddrEqual(rsaddr,rsaddrlen,
(struct sockaddr*)&peer_addr,
peer_addr_len,I2SADDR_ADDR) <= 0){
goto again;
}
}
else if(I2SockAddrEqual(rsaddr,rsaddrlen,
(struct sockaddr*)&peer_addr,
peer_addr_len,I2SADDR_ALL) <= 0){
goto again;
}

#ifdef OWP_EXTRA_DEBUG
{
Expand Down
Loading