Skip to content

Commit

Permalink
Fix detection of incoming v3.1/v3.1.1 bridges.
Browse files Browse the repository at this point in the history
Closes #1263. Thanks to vrst37.
  • Loading branch information
ralight committed May 8, 2019
1 parent 995f90d commit cd3877e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.txt
@@ -1,3 +1,10 @@
1.6.3 - 201905xx
================

Broker:
- Fix detection of incoming v3.1/v3.1.1 bridges. Closes #1263.


1.6.2 - 20190430
================

Expand Down
7 changes: 7 additions & 0 deletions src/handle_connect.c
Expand Up @@ -426,9 +426,16 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
goto handle_connect_error;
}
context->protocol = mosq_p_mqtt31;
if((protocol_version&0x80) == 0x80){
context->is_bridge = true;
}
}else if(!strcmp(protocol_name, PROTOCOL_NAME)){
if((protocol_version&0x7F) == PROTOCOL_VERSION_v311){
context->protocol = mosq_p_mqtt311;

if((protocol_version&0x80) == 0x80){
context->is_bridge = true;
}
}else if((protocol_version&0x7F) == PROTOCOL_VERSION_v5){
context->protocol = mosq_p_mqtt5;
}else{
Expand Down
52 changes: 52 additions & 0 deletions test/broker/06-bridge-no-local.py
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

# Check whether an incoming bridge connection receives its own messages. It
# shouldn't because for v3.1 and v3.1.1 we have no-local set for all bridges.

from mosq_test_helper import *

port = mosq_test.get_port()

def do_test(proto_ver_connect, proto_ver_msgs, sub_opts):
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("bridge-test", keepalive=keepalive, proto_ver=proto_ver_connect)
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver_msgs)

mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "loop/test", 0 | sub_opts, proto_ver=proto_ver_msgs)
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver_msgs)

publish_packet = mosq_test.gen_publish("loop/test", qos=0, payload="message", proto_ver=proto_ver_msgs)

pingreq_packet = mosq_test.gen_pingreq()
pingresp_packet = mosq_test.gen_pingresp()

port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)

try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)

mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")

sock.send(publish_packet)
mosq_test.do_send_receive(sock, pingreq_packet, pingresp_packet, "pingresp")
rc = 0

sock.close()
finally:
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
exit(rc)

do_test(128+3, 3, 0)
do_test(128+4, 4, 0)
do_test(5, 5, mqtt5_opts.MQTT_SUB_OPT_NO_LOCAL)

exit(0)


1 change: 1 addition & 0 deletions test/broker/Makefile
Expand Up @@ -129,6 +129,7 @@ endif
./06-bridge-br2b-remapping.py
./06-bridge-fail-persist-resend-qos1.py
./06-bridge-fail-persist-resend-qos2.py
./06-bridge-no-local.py
./06-bridge-per-listener-settings.py
./06-bridge-reconnect-local-out.py

Expand Down
7 changes: 4 additions & 3 deletions test/broker/test.py
Expand Up @@ -96,16 +96,17 @@

(2, './06-bridge-b2br-disconnect-qos1.py'),
(2, './06-bridge-b2br-disconnect-qos2.py'),
(2, './06-bridge-b2br-late-connection-retain.py'),
(2, './06-bridge-b2br-late-connection.py'),
(2, './06-bridge-b2br-remapping.py'),
(2, './06-bridge-br2b-disconnect-qos1.py'),
(2, './06-bridge-br2b-disconnect-qos2.py'),
(2, './06-bridge-br2b-remapping.py'),
(2, './06-bridge-fail-persist-resend-qos1.py'),
(2, './06-bridge-fail-persist-resend-qos2.py'),
(2, './06-bridge-reconnect-local-out.py'),
(1, './06-bridge-no-local.py'),
(3, './06-bridge-per-listener-settings.py'),
(2, './06-bridge-b2br-late-connection.py'),
(2, './06-bridge-b2br-late-connection-retain.py'),
(2, './06-bridge-reconnect-local-out.py'),

(1, './07-will-delay-reconnect.py'),
(1, './07-will-delay-recover.py'),
Expand Down

0 comments on commit cd3877e

Please sign in to comment.