[英]Multicast packet not arrived inside podman correctly. Workaround found, but unclear if it is a firewalld issue or a podman issue?
I am becoming crazy with the firewalld, podman and UDP/Multicast.我对 firewalld、podman 和 UDP/Multicast 越来越感兴趣。 While I see UDP packets arriving in podman;
当我看到 UDP 数据包到达 podman 时; confirmed using
tcpdump
command.使用
tcpdump
命令确认。 It seems I am unable to configure using a customized firewalld zone with name knx_multicast
that should accept only when UDP packet is from multicast group 224.0.23.12:3671
.似乎我无法使用名称为
knx_multicast
的自定义防火墙区域进行配置,该区域仅在 UDP 数据包来自多播组224.0.23.12:3671
时才应接受。
Given minimal example, written in Java:给出用 Java 编写的最小示例:
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
public class Test {
public static void main(String[] args) throws Throwable {
final var group = InetAddress.getByName("224.0.23.12");
final var s = new MulticastSocket(3671);
final var ni = NetworkInterface.getByName("enp1s0");
s.setNetworkInterface(ni);
s.joinGroup(group);
System.out.println("Start listening ... @" + ni );
final var buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.receive(recv);
System.out.println(recv.getData());
s.leaveGroup(group);
s.close();
}
}
I have the firewalld configured as:我将 firewalld 配置为:
knx_multicast (active)
target: default
icmp-block-inversion: no
interfaces:
sources: 224.0.23.12
services:
ports: 3671/udp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
public (active)
target: default
icmp-block-inversion: no
interfaces: enp1s0
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Testing multicast packet on CentOS 8.1在 CentOS 8.1 上测试多播数据包
Now I tested first in CentOS 8.1 running and it works as the I get some data (see: [B@61a52fbd
below)现在我首先在 CentOS 8.1 运行中进行了测试,它在我获得一些数据时工作(参见:
[B@61a52fbd
下面)
[root@PIT-Server ~]# javac Test.java && java Test
Start listening ... @name:enp1s0 (enp1s0)
[B@61a52fbd
Testing multicast packet using PODMAN on CentOS 8.1在 CentOS 8.1 上使用 PODMAN 测试多播数据包
Next step is now to test within a podman container (image: 'adoptopenjdk/openjdk11:latest' which is running on "Ubuntu 18.04.3 LTS") using: podman run --rm -it --net host docker.io/adoptopenjdk/openjdk11 /bin/bash
下一步是在 podman 容器中进行测试(图像:'adoptopenjdk/openjdk11:latest',它在“Ubuntu 18.04.3 LTS”上
podman run --rm -it --net host docker.io/adoptopenjdk/openjdk11 /bin/bash
)使用: podman run --rm -it --net host docker.io/adoptopenjdk/openjdk11 /bin/bash
Inside the podman I also see the UDP packets arriving from the PIT-KNX (a KNX router).在 podman 内部,我还看到来自 PIT-KNX(KNX 路由器)的 UDP 数据包。
root@PIT-Server:/tcpdump -i enp1s0 udp port 3671
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp1s0, link-type EN10MB (Ethernet), capture size 262144 bytes
19:49:35.583901 IP PIT-KNX.pit-router.3671 > 224.0.23.12.3671: UDP, length 17
19:49:36.032139 IP PIT-KNX.pit-router.3671 > 224.0.23.12.3671: UDP, length 18
... lines omitted ...
Starting the same java application (which was working outside of container environment) I am unable to get any data (no byte array arrived after "Start listening")启动相同的 java 应用程序(在容器环境之外工作)我无法获取任何数据(“开始监听”后没有字节数组到达)
root@PIT-Server:/# javac Test.java && java Test
Start listening ... @name:enp1s0 (enp1s0)
Workaround (firewalld)解决方法(防火墙)
After investigating several hours/coffees I figured out that allowing port in the zone=knx_multicast is not enough.在调查了几个小时/咖啡后,我发现在 zone=knx_multicast 中允许端口是不够的。 I have to add the port to
zone=public
too, using: firewall-cmd --add-port=3671/udp
.我也必须将端口添加到
zone=public
,使用: firewall-cmd --add-port=3671/udp
。 The config of firewalld is now: firewalld 的配置现在是:
knx_multicast (active)
target: default
icmp-block-inversion: no
interfaces:
sources: 224.0.23.12
services:
ports: 3671/udp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
public (active)
target: default
icmp-block-inversion: no
interfaces: enp1s0
sources:
services: cockpit dhcpv6-client ssh
ports: 3671/udp <== ADDED!!!! (that one fixes the problem)
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Re-Testing multicast packet using PODMAN on CentOS 8.1在 CentOS 8.1 上使用 PODMAN 重新测试多播数据包
By re-running the java application I am now able to see the arriving UDP multicast packet (see: [B@61a52fbd
below)通过重新运行 java 应用程序,我现在可以看到到达的 UDP 多播数据包(参见:
[B@61a52fbd
下面)
root@PIT-Server:/# javac Test.java && java Test
Start listening ... @name:enp1s0 (enp1s0)
[B@61a52fbd
My questions ... what happened?我的问题......发生了什么? Next steps?
下一步?
Can anyone help me to understand what exactly the issue is?任何人都可以帮助我了解问题究竟是什么? Why do I have to add port to
zone=public
too?为什么我也必须将端口添加到
zone=public
? Is this a bug or a configuration issue on my side?这是我这边的错误还是配置问题? How can I resolve it without adding the port to the
zone=public
?如何在不将端口添加到
zone=public
情况下解决它? Do I have a misunderstanding?我有什么误解吗?
I would have been more comfortable by adding a new firewalld zone (called knx_multicast
) only;如果只添加一个新的 firewalld 区域(称为
knx_multicast
),我会更舒服; and keep the configuration of firewalld public
zone untouched.并保持 firewalld
public
区域的配置不变。 Suggestions?建议?
Thank you, Christoph谢谢你,克里斯托夫
Thanks to @Ron Maupin for pointing the issue.感谢@Ron Maupin 指出这个问题。 My firewall configuration was wrong.
我的防火墙配置错误。
The issue has been resolved by creating a new service:该问题已通过创建新服务解决:
firewall-cmd --permanent --new-service=knx
firewall-cmd --permanent --service=knx --set-description="KNXnet/IP is a part of KNX standard for transmission of KNX telegrams via Ethernet"
firewall-cmd --permanent --service=knx --set-short=KNX
firewall-cmd --permanent --service=knx --add-port=3671/udp
To make able to add the newly created service, reload the firewalld and add it为了能够添加新创建的服务,重新加载 firewalld 并添加它
firewall-cmd --reload
firewall-cmd --permanent --add-service=knx
This will create a service file: /etc/firewalld/services/knx.xml
with following content:这将创建一个服务文件:
/etc/firewalld/services/knx.xml
,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>KNX</short>
<description>KNXnet/IP is a part of KNX standard for transmission of KNX telegrams via Ethernet</description>
<port port="3671" protocol="udp"/>
</service>
And the firewall config will look like:防火墙配置将如下所示:
public (active)
target: default
icmp-block-inversion: no
interfaces: enp1s0
sources:
services: cockpit dhcpv6-client knx ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.