Skip to content

Commit 09cbd28

Browse files
rlubosMaureenHelm
authored andcommitted
net: connection: Use NET_CONN_*_PORT_SPEC flag when comparing ports
The NET_CONN_LOCAL/REMOTE_PORT_SPEC flags were set on the connection but not really used. At the same time, when remote address was being cleared, only the flag was unset, but the actual port number left intact. This could lead to false port comparisons when remote address was cleared from the connection context. In order to avoid that, use the NET_CONN_*_PORT_SPEC flags to determine whether to compare local/remote ports instead of checking the port value right away (which may not be valid anymore if the flag is unset). Also align with MISRA rules when comparing flags in other cases. Signed-off-by: Robert Lubos <[email protected]>
1 parent 841035a commit 09cbd28

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

subsys/net/ip/connection.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,22 +970,22 @@ enum net_verdict net_conn_input(struct net_pkt *pkt,
970970
/* Is the candidate connection matching the packet's TCP/UDP
971971
* address and port?
972972
*/
973-
if (net_sin(&conn->remote_addr)->sin_port &&
973+
if ((conn->flags & NET_CONN_REMOTE_PORT_SPEC) != 0 &&
974974
net_sin(&conn->remote_addr)->sin_port != src_port) {
975975
continue; /* wrong remote port */
976976
}
977977

978-
if (net_sin(&conn->local_addr)->sin_port &&
978+
if ((conn->flags & NET_CONN_LOCAL_PORT_SPEC) != 0 &&
979979
net_sin(&conn->local_addr)->sin_port != dst_port) {
980980
continue; /* wrong local port */
981981
}
982982

983-
if ((conn->flags & NET_CONN_REMOTE_ADDR_SET) &&
983+
if ((conn->flags & NET_CONN_REMOTE_ADDR_SET) != 0 &&
984984
!conn_addr_cmp(pkt, ip_hdr, &conn->remote_addr, true)) {
985985
continue; /* wrong remote address */
986986
}
987987

988-
if ((conn->flags & NET_CONN_LOCAL_ADDR_SET) &&
988+
if ((conn->flags & NET_CONN_LOCAL_ADDR_SET) != 0 &&
989989
!conn_addr_cmp(pkt, ip_hdr, &conn->local_addr, false)) {
990990

991991
/* Check if we could do a v4-mapping-to-v6 and the IPv6 socket

0 commit comments

Comments
 (0)