Linux kernel cannot receive multicast - linux

I built a Linux kernel with CONFIG_IP_MULTICAST=y,however no UDP multicast package received in this kernel while UDP unicast works well.
ethtool -S eth0 | grep multicast
txmulticastframes_g: 0
txmulticastframes_gb: 0
rxmulticastframes_g: 0
Any hints how can I solve this problem?
Thx. Forrest G
=================================================================================
Additional:
tcpdump can get the packet
root#JHI # ./tcpdump port 3702
device eth0 entered promiscuous mode
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
-7:-48:-19.4151 IP 192.168.42.212.3702 > 239.255.255.250.3702: UDP, length 787
-7:-48:-19.4661 IP 192.168.42.212.3702 > 239.255.255.250.3702: UDP, length 803
^C
2 packets captured
2 padevice eth0 left promiscuous mode
ckets received by filter
0 packets dropped by kernel
I write this WS-devicediscovery function with gSOAP. It works on X86 machine. When running on ARM device, it can send out igmp packet but not receive anything.
void wsdd()
{
struct soap *soap_udp;
struct ip_mreq mreq;
soap_udp=soap_new();
soap_init1(soap_udp, SOAP_IO_UDP|SOAP_IO_FLUSH);
if (!soap_valid_socket(soap_bind(soap_udp, NULL, 3702, 100)))
{
soap_print_fault(soap_udp, stderr);
}
mreq.imr_multiaddr.s_addr = inet_addr("239.255.255.250");
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if(setsockopt(soap_ud->master,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq))==-1) {
perror("membership error\n");
}
int loop = 1;
int sock_opt = 1;
if ((setsockopt(soap_udp->master, SOL_SOCKET, SO_REUSEADDR, (void *) &sock_opt,
sizeof (sock_opt))) == -1) {
printf("setsockopt\n");
}
if ((setsockopt(soap_udp->master, IPPROTO_IP, IP_MULTICAST_LOOP,
&loop, sizeof (loop))) == -1) {
printf("setsockopt\n");
}
while(1){
soap_accept(soap_udp);
soap_serve(soap_udp);
soap_end(soap_udp);
}
}
Then I have tried these things but still not work
route add -net 224.0.0.0 netmask 240.0.0.0 eth0
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter

Problem solved by changing..
ifconfig eth0 promisc
Can anyone explain the principle?

Related

Docker Compose: Use static and dynamic network interface in container

I have an app that needs to access the internet and a local resource in a local area network. I want to run this app with docker compose. My host-system has 4 physical network ports and I connect with two Ethernet cables to the local-area net and the internet.
Host system can ping addresses from both networks successfully. But from inside the container I get no ping to outside. Tried with ping, tried a specific port with nmap, to no avail.
I have the following output when I analyze the network interfaces:
# network configuration host-system
enp03s31f6:
IPv4: XXX.XXX.XXX.XX
IPv6: XXXX:XXXX:XXXX:XXXX
enp2s0:
IPv4: 192.168.163.222 # <- host computer's address in local network
IPv6: XXXX:XXXX:XXXX:XXXX <- somehow an IPv6 address is assigned but only IPv4 is relevant
My docker-compose.yml is posted below:
# docker-compose.yml
version: "3.6"
networks:
dhcp_net:
app_local_net:
driver_opts:
com.docker.network.bridge.host_binding_ipv4: "192.168.163.222"
ipam:
driver: default
config:
- subnet: "192.168.163.0/24"
services:
main:
build:
context: .
image: "my_custom_app"
ports:
- "192.168.163.222:520:520"
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"
networks:
dhcp_net:
app_local_net:
ipv4_address: 192.168.163.222
command: ./start_my_app
Of course there are more services in the compose-file, I left them out for better focus.
when I go into the container while it is running, I can successfully install iputils-ping and ping internet addresses. When I try to ping an address in the local network (app_local_net), host is unreachable.
When I go and inspect the container's network, following output is generated:
docker network inspect my_app_app_local_net
[
{
"Name": "my_app_app_local_net",
"Id": "b43184e60537541a764c3479ece9e861c49169b7629f810f532276b9949b522f",
"Created": "2021-11-17T17:37:50.935949741+01:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.163.0/24"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"e3ae8336c0ac18f7d164a15bd9e7f590ffa18b8b1688900a7ad639f92ba7bcf2": {
"Name": "my_app_main_1",
"EndpointID": "4d2fa1e37a823144fe1ffd3ea4f0720d8be83d4fc17629d5921cbd781e775838",
"MacAddress": "02:42:c0:a8:a3:de",
"IPv4Address": "192.168.163.222/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.host_binding_ipv4": "192.168.163.222"
},
"Labels": {
"com.docker.compose.network": "app_local_net",
"com.docker.compose.project": "my_app",
"com.docker.compose.version": "1.29.2"
}
}
]
ifconfig shows the following:
root#container$:ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.21.0.2 netmask 255.255.0.0 broadcast 172.21.255.255
ether 02:42:ac:15:00:02 txqueuelen 0 (Ethernet)
RX packets 1132 bytes 1641413 (1.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 870 bytes 60160 (60.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.163.222 netmask 255.255.255.0 broadcast 192.168.163.255
ether 02:42:c0:a8:a3:de txqueuelen 0 (Ethernet)
RX packets 59 bytes 7508 (7.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6 bytes 252 (252.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 188.10.163.4 netmask 255.255.255.0 broadcast 188.10.163.255
ether 02:42:bc:0a:a3:04 txqueuelen 0 (Ethernet)
RX packets 25 bytes 2975 (2.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 16 bytes 1716 (1.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 1716 (1.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
if I do a $ ping -I eth1 192.168.163.102 inside the container, it will not work.
I see the following questions as related and already incorporated advice, but somehow I am stuck:
Docker compose yml static IP addressing
How can I make docker-compose bind the containers only on defined network instead of 0.0.0.0?
Docker Compose with static public IP over LAN but different with Host IP
Provide static IP to docker containers via docker-compose
Is there anything I am missing? Thanks for any help in advance :-)

Why U disk couldnot be addressed when unplug a usb speaker from the usb 3.0 port?

My board has a usb3.0 port and a usb2.0 port. The bug occurred in the usb3.0 port. The Linux kernel version is 3.10.65.
The script that makes the bug:
plug a USB speaker in the usb3.0 port.
play audio in the USB speaker continuously.
unplug the USB speaker, Not stop audio play when unplug.
plug a usb3.0 disk in the same that usb3.0 port.
then the USB host controller couldn't address the U Disk.
System report the following log:
#
#
#
# ./test.sh
[ 68.036091] usb 3-1: USB disconnect, device number 2
[ 68.041659] cannot submit urb (err = -19)
[ 78.860028] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 84.070030] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 84.280026] usb 4-1: device not accepting address 2, error -62
[ 89.460027] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 94.670025] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 94.880020] usb 4-1: device not accepting address 3, error -62
[ 100.060036] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 105.270044] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 105.480024] usb 4-1: device not accepting address 4, error -62
[ 110.660024] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 115.870026] xhci-hcd xhci-hcd.0.auto: Timeout while waiting for address device command
[ 116.080020] usb 4-1: device not accepting address 5, error -62
[ 116.086478] hub 4-0:1.0: unable to enumerate USB device on port 1
After a long time debug, I find if I add the debug info , the bug never happen. But I don't know why.
void usb_set_device_state(struct usb_device *udev,
enum usb_device_state new_state)
{
unsigned long flags;
int wakeup = -1;
spin_lock_irqsave(&device_state_lock, flags);
if (udev->state == USB_STATE_NOTATTACHED)
; /* do nothing */
else if (new_state != USB_STATE_NOTATTACHED) {
/* root hub wakeup capabilities are managed out-of-band
* and may involve silicon errata ... ignore them here.
*/
if (udev->parent) {
if (udev->state == USB_STATE_SUSPENDED
|| new_state == USB_STATE_SUSPENDED)
; /* No change to wakeup settings */
else if (new_state == USB_STATE_CONFIGURED)
wakeup = (udev->quirks &
USB_QUIRK_IGNORE_REMOTE_WAKEUP) ? 0 :
udev->actconfig->desc.bmAttributes &
USB_CONFIG_ATT_WAKEUP;
else
wakeup = 0;
}
if (udev->state == USB_STATE_SUSPENDED &&
new_state != USB_STATE_SUSPENDED)
udev->active_duration -= jiffies;
else if (new_state == USB_STATE_SUSPENDED &&
udev->state != USB_STATE_SUSPENDED)
udev->active_duration += jiffies;
udev->state = new_state;
} else
recursively_mark_NOTATTACHED(udev);
if (new_state == USB_STATE_NOTATTACHED) {
printk("[%s %d] .\n", __func__, __LINE__);
printk("[%s %d] .\n", __func__, __LINE__);
printk("[%s %d] .\n", __func__, __LINE__);
}
spin_unlock_irqrestore(&device_state_lock, flags);
if (wakeup >= 0)
device_set_wakeup_capable(&udev->dev, wakeup);
}
enter code here

How to insert lines after second pattern with linux sed command

I want to insert this block:
host client3 {
hardware ethernet c0:03:03:bc:30:fa;
}
after this block:
subnet 11.10.0.0 netmask 255.255.255.0 {
range 11.10.1.2 11.10.1.254;
group {
filename "10M-5M-OKS2016NOV.cm";
The line: filename "10M-5M-OKS2016NOV.cm";
apears multiple times in the file. But only once inside subnet 11.10.0.0 netmask 255.255.255.0 {
Until now I can print the subnet block until the "filename":
sed -n -e :a -e '/subnet 11\.10\.0\.0 netmask 255\.255\.255\.0/,/}/{/filename "10M-5M-OKS2016NOV\.cm";/!{$!{N;ba};};p;}' dhcpd.conf
but when I try:
sed -n -e :a -e '/subnet 11\.10\.0\.0 netmask 255\.255\.255\.0/,/}/{/filename "10M-5M-OKS2016NOV\.cm";/!{$!{N;ba};};a\ \thost client3 {\n\thardware ethernet c0:03:03:bc:30:fa;\n\t}\n;}' dhcpd.conf
I get:
sed: -e expression #1, char 0: unmatched `{'
subnet 10.10.0.0 netmask 255.255.255.0 {
range 10.10.0.2 10.10.0.254;
group {
filename "10M-5M-OKS2016NOV.cm";
host client1 {
hardware ethernet a0:b4:3d:bc:df:fa;
}
host client2 {
hardware ethernet 90:6e:bb:ba:cd:d4;
}
}
}
subnet 11.10.0.0 netmask 255.255.255.0 {
range 11.10.1.2 11.10.1.254;
group {
filename "10M-5M-OKS2016NOV.cm";
host client1 {
hardware ethernet c0:14:e3:bc:df:fa;
}
host client2 {
hardware ethernet 90:6e:fb:ba:3d:04;
}
}
}
subnet 12.10.0.0 netmask 255.255.255.0 {
range 12.10.2.2 12.10.2.254;
group {
filename "10M-5M-OKS2016NOV.cm";
host client1 {
hardware ethernet c0:a4:3d:bc:df:fa;
}
host client2 {
hardware ethernet 90:6e:bb:ca:3d:04;
}
}
}
Please try something like:
#!/bin/bash
# define newline and tab characters for replacement
NL=$'\n'
NL="\\$NL"
TAB=$'\t'
TAB="\\$TAB"
sed '
:l
N
$!b l
# first of all slurp all lines in the pattern space
# and perform the replacement over the lines
s/subnet 11\.10\.0\.0 netmask 255\.255\.255\.0[^}]*filename "10M-5M-OKS2016NOV\.cm";/&'"$NL$TAB"'host client3 {'"$NL$TAB$TAB"'hardware ethernet c0:03:03:bc:30:fa;'"$NL$TAB"'}/g
' dhcpd.conf
It yields the following output by using the posted lines as dhcpd.conf,
subnet 10.10.0.0 netmask 255.255.255.0 {
range 10.10.0.2 10.10.0.254;
group {
filename "10M-5M-OKS2016NOV.cm";
host client1 {
hardware ethernet a0:b4:3d:bc:df:fa;
}
host client2 {
hardware ethernet 90:6e:bb:ba:cd:d4;
}
}
}
subnet 11.10.0.0 netmask 255.255.255.0 {
range 11.10.1.2 11.10.1.254;
group {
filename "10M-5M-OKS2016NOV.cm";
host client3 {
hardware ethernet c0:03:03:bc:30:fa;
}
host client1 {
hardware ethernet c0:14:e3:bc:df:fa;
}
host client2 {
hardware ethernet 90:6e:fb:ba:3d:04;
}
}
}
subnet 12.10.0.0 netmask 255.255.255.0 {
range 12.10.2.2 12.10.2.254;
group {
filename "10M-5M-OKS2016NOV.cm";
host client1 {
hardware ethernet c0:a4:3d:bc:df:fa;
}
host client2 {
hardware ethernet 90:6e:bb:ca:3d:04;
}
}
}
It initially slurps all the lines at first to process multi lines efficiently.
It assumes the right curly brace } does not appear in the search target block
to achieve the shortest match in regex.
Hope this helps.
This might work for you (GNU sed):
sed '/subnet 11\.10\.0\.0 netmask 255\.255\.255\.0/{:a;n;/filename "10M-5M-OKS2016NOV\.cm";/!ba;p;s/\S.*/host client3 {/p;s// hardware ethernet c0:03:03:bc:30:fa;/p;s//}/}' file
This finds the first line containing subnet 11.10.0.0 netmask 255.255.255.0 and then reads on further until the line containing filename "10M-5M-OKS2016NOV.cm";. After printing that line it uses the line as a template to format the required detail.
Another solution, using a preformed insertion file:
cat <<\! | sed '/subnet 11\.10\.0\.0 netmask 255\.255\.255\.0/!b;:a;n;/filename "10M-5M-OKS2016NOV\.cm";/!ba;r /dev/stdin' file
host client3 {
hardware ethernet c0:03:03:bc:30:fa;
}
!
sed is great as a stream editor, that means to process multiple times the same actions. Here you just want to insert once a bloc of text. That would be much simpler (more readable and maintenable) with ed:
ed dhcpd.conf <<EOF
/subnet 11.10.0.0/
/filename/
a
host client3 {
hardware ethernet c0:03:03:bc:30:fa;
}
.
w
q
EOF
Beware: ed is a file editor. That means that the dhcpd.conf file will be changed by the above script. Make sure to have a backup if things goes wrong...

Why linux reuses 'time_wait' port?

As I know, tcp port in 'time_wait' stat cann't be used. However, in my experiment, server reuses the 'time_wait' port? Why?
Firstly, in client machine, type command ehco 40000 40001 > /proc/sys/net/ipv4/ip_local_port_range. So, the maximum number of TCP ports is 2.
server code
while (1) {
int len = sizeof(struct sockaddr);
fd = accept(sfd, &remote, &len);
read(fd, buf, sizeof(buf));
close(fd);
}
client code
for (i = 0; i < 3; i++)
{
sleep(1);
pid_t pid = fork();
if (pid == 0)
{
handler();
exit(0);
}
}
void handler()
{
* ............. */
res = connect(sfd, result->ai_addr, result->ai_addrlen);
if (res == -1) {
perror("error");
exit(1);
}
printf("connect\n");
}
show
[root#livecd ~]# ./client
connect
[root#livecd ~]# connect
connect
It's up to 3 connections. I think, 2 connections at most. Why ?
server has 2 timewait connections.
[root#livecd ~]# netstat -anp | grep TIME
tcp 192.168.88.131:2016 192.168.88.132:40000 TIME_WAIT
tcp 192.168.88.131:2016 192.168.88.132:40001 TIME_WAIT
Environment
Linux livecd.centos 2.6.32-642.el6.i686 #1 SMP Tue May 10 16:13:51 UTC 2016
server config
[root#livecd ~]# cat /proc/sys/net/ipv4/tcp_fin_timeout
60
[root#livecd ~]# cat /proc/sys/net/ipv4/tcp_tw_recycle
0
[root#livecd ~]# cat /proc/sys/net/ipv4/tcp_tw_reuse
0
client config
[root#livecd ~]# cat /proc/sys/net/ipv4/ip_local_port_range
40000 40001
Important
I also try ubuntu server 14.04, but got the same result.

systemtap tcp connections script error

i am trying to run this script , and it shows no tcp connections any ideas? OS: centos 6.3
#! /usr/bin/env stap
probe begin {
printf("%6s %16s %6s %6s %16s\n",
"UID", "CMD", "PID", "PORT", "IP_SOURCE")
}
probe kernel.function("tcp_accept").return?,
kernel.function("inet_csk_accept").return? {
sock = $return
if (sock != 0)
printf("%6d %16s %6d %6d %16s\n", uid(), execname(), pid(),
inet_get_local_port(sock), inet_get_ip_source(sock))
}
OUTPUT:
[root#server src]# ./tcp_con.stp
Missing separate debuginfos, use: debuginfo-install kernel-2.6.32-279.1.1.el6.centos.plus.x86_64
UID CMD PID PORT IP_SOURCE
Follow systemtap's advice and install kernel-debuginfo.
The question marks after both kernel.function() probes let stap quietly drop both of those.

Resources