MQTT 畸形数据包

问题描述 投票:0回答:2

在docker中运行mosquito Broker,broker ip地址是172.18.5.10,docker网络网关是172.18.5.1。还有一些其他码头工人连接到该网络,我也有几个 MQTT 设备/程序订阅并发布到 Mosquito 代理并且工作得很好。

问题是我每隔约 40 秒就会收到以下错误。

2023/02/22T14:20:09: New connection from 172.18.5.1:47008 on port 1883.
2023/02/22T14:20:09: Client <unknown> disconnected due to malformed packet.
2023/02/22T14:20:37: New connection from 172.18.5.1:47162 on port 1883.
2023/02/22T14:20:37: Client <unknown> disconnected due to malformed packet.
2023/02/22T14:21:05: New connection from 172.18.5.1:47270 on port 1883.
2023/02/22T14:21:05: Client <unknown> disconnected due to malformed packet.
2023/02/22T14:21:33: New connection from 172.18.5.1:47418 on port 1883.
2023/02/22T14:21:33: Client <unknown> disconnected due to malformed packet.
2023/02/22T14:22:01: New connection from 172.18.5.1:47538 on port 1883.
2023/02/22T14:22:01: Client <unknown> disconnected due to malformed packet.
2023/02/22T14:22:29: New connection from 172.18.5.1:47674 on port 1883.
2023/02/22T14:22:29: Client <unknown> disconnected due to malformed packet.
2023/02/22T14:22:57: New connection from 172.18.5.1:47782 on port 1883.

这是wireshark 的结果

2023/02/22T14:21:05: New connection from 172.18.5.1:47270 on port 1883.
2023/02/22T14:21:05: Client <unknown> disconnected due to malformed packet.

不同源端口的更详细错误图像

这是良好和不良连接的示例,良好的连接来自本地 IP 地址范围,但这种格式错误的连接始终来自网络网关:

2023/02/21T22:38:03: New client connected from 192.168.3.8:52207 as sw-tasmota-hall (p2, c1, k30, u'data').
2023/02/21T22:38:04: New connection from 192.168.3.1:57113 on port 1883.
2023/02/21T22:38:04: New client connected from 192.168.3.1:57113 as switch-tasmota-bath (p2, c1, k30, u'data').
2023/02/21T22:38:04: New connection from 192.168.2.4:58631 on port 1883.
2023/02/21T22:38:04: New client connected from 192.168.2.4:58631 as node-tasmota-garage (p2, c1, k30, u'data').
2023/02/21T22:38:06: New connection from 172.18.5.1:48908 on port 1883.
2023/02/21T22:38:06: Client <unknown> disconnected due to malformed packet.
2023/02/21T22:38:28: New connection from 172.18.5.1:49018 on port 1883.
2023/02/21T22:38:28: Client <unknown> disconnected due to malformed packet.
2023/02/21T22:38:50: New connection from 172.18.5.1:49160 on port 1883.
2023/02/21T22:38:50: Client <unknown> disconnected due to malformed packet.

Docker 撰写:

version: '3'

services:
  mosquitto:
    image: eclipse-mosquitto:2.0.15
    container_name: mosquitto
    restart: unless-stopped
    environment:
      - TZ=Europe/Prague
    ports:
      - "1883:1883"
    volumes:
      - /share/Container/mosquitto/data:/mosquitto/data
      - /share/Container/mosquitto/config:/mosquitto/config
      - /share/Container/mosquitto/log:/mosquitto/log
      - /etc/localtime:/etc/localtime:ro      
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://192.168.1.106:514"
        tag: "{{.Name}}/{{.ImageName}}"
    networks:
      ha_net:
         ipv4_address: 172.18.5.10
networks:
  ha_net:
    external: true

mosquitto.conf

persistence true
persistence_location /mosquitto/data/
persistence_file mosquitto.db

listener 1883

allow_anonymous true

log_type error
log_type warning
log_type notice
log_type information
log_dest stdout
log_timestamp true
log_timestamp_format %Y/%m/%dT%H:%M:%S

password_file /mosquitto/config/pwfile

我正在寻求帮助,如何检测导致此问题的设备/主机/程序的 IP 地址。

谢谢, 萨尔夫q

docker mqtt docker-networking malformed
2个回答
0
投票

我能够通过在主机网络模式而不是自定义桥接网络模式下运行mosquito docker来解决这个问题(由于数据包格式错误而断开连接)。

但是,我无法确定由于 docker 自定义桥接网络上的数据包格式错误而导致断开连接的根本原因,但不是在主机网络模式下。

工作中的 docker-compose

version: '3'

services:
  mosquitto:
    image: eclipse-mosquitto:2.0.15
    container_name: mosquitto
    restart: unless-stopped
    network_mode: host
    environment:
      - TZ=Europe/Prague
    volumes:
      - /share/Container/mosquitto/data:/mosquitto/data
      - /share/Container/mosquitto/config:/mosquitto/config
      - /share/Container/mosquitto/log:/mosquitto/log
      - /etc/localtime:/etc/localtime:ro      
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://192.168.1.106:514"
        tag: "{{.Name}}/{{.ImageName}}"

0
投票

我遇到了同样的问题,但这种情况发生在带有 pubsubclient 的 esp32 上。主要问题是由我的设备在多个设备上连接到代理的相同 ID 引起的。确保您生成的每个连接都有一个唯一的 ID。

© www.soinside.com 2019 - 2024. All rights reserved.