loopback network kernel module not working - linux-device-driver

I am new to kernel module development. I am trying to development a pseudo network driver operates in loopback mode without any actual device. My goal is to use the following setup:
iperf -s -u.........iperf -c 192.168.1.1 -p 5001 -u
======..............===========
|...if0....|.............|........if1.........|
======..............===========
| |
/|\ \|/
| |
---------------
I have registered two interface from the driver. Then I modified the UDP packet received from if1 so that it appeared as it was received at if0. But it never reaches to the iperf server application listening on all udp if's udp port. But whenever I sniffed the packet via wireshark on if0, it seems that the packet is being received at if0. But for some reason it is not going through the network stack.
any clues?
Both the ip checksum & udp checksum have recalculated and verified (using wireshark). I am using netif_rx to indicate packet to the other interface handle (if0 handle).
I have only used 5 function ptr callbacks {open, close, xmit_start, get_stats & config} for network operations. Also checksum is set to UNNECESSARY. IF flag has been set to indicate NO_ARP.
EDIT: IP ADDR OUTPUT
eth1: mtu 1500 qdisc
pfifo_fast state UP qlen 1000 link/ether 00:e0:ff:00:00:e0 brd
ff:ff:ff:ff:ff:ff inet 192.168.1.1/24 brd 192.168.1.255 scope globa eth1 valid_lft
forever preferred_lft forever 4:
eth2: mtu 1500 qdisc pfifo_fast
state UP qlen 1000 link/ether 00:e0:ff:40:00:e0 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.1/24 brd 192.168.2.255 scope global eth2 valid_lft
forever preferred_lft forever

Ok I have figured it out.
I feel stupid not to think about it. The packet was dropped due to the routing issue.
The received packet at the receiving IF must have the same network as the IF.
So, if the IF has 192.168.1.1/24, the routing system only accepts packet originated from 192.168.1.X/24.
I didn't noticed it until I tried with the single IF loopback.
Can anyone explain why it has happened?

Related

Connman does not seem to start a DHCP server

I am creating a USB gadget with Yocto, which loads the gadget kernel modules and is recognized by my host as a network interface (usb0). On the gadget, I have connman installed and running. I am using the default configuration (no /etc/connman/main.conf), though I have tried to manually enable the gadget in /var/lib/connman/settings:
~# cat /var/lib/connman/settings
[global]
OfflineMode=false
[Gadget]
Enable=true
Tethering=true
However, when I try to get an IP from the host (with e.g. dhcpcd usb0), it does not seem to find a DHCP server, and I get an IPv4LL instead. The journalctl of my host looks like this:
avahi-daemon[812]: Registering new address record>
dhcpcd[875]: usb0: soliciting an IPv6 router
dhcpcd[875]: usb0: soliciting a DHCP lease
dhcpcd[875]: usb0: probing for an IPv4LL address
dhcpcd[875]: usb0: using IPv4LL address 169.254.1>
avahi-daemon[812]: Joining mDNS multicast group o>
avahi-daemon[812]: New relevant interface usb0.IP>
dhcpcd[875]: usb0: adding route to 169.254.0.0/16
avahi-daemon[812]: Registering new address record>
dhcpcd[875]: usb0: no IPv6 Routers available
Note that on the gadget, I created a service profile to give an IP to the usb0 interface, which gets:
3: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP8000> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 66:7e:25:f1:3d:cf brd ff:ff:ff:ff:ff:ff
inet 10.42.0.2/24 brd 10.42.0.255 scope global usb0
valid_lft forever preferred_lft forever
inet6 fe80::647e:25ff:fef1:3dcf/64 scope link
valid_lft forever preferred_lft forever
This is the service config:
[service_gadget]
Type = gadget
IPv4 = 10.42.0.2/255.255.255.0/10.42.0.1
What could I be missing for Connman to start a DHCP server and successfully assign an IP to the host usb0 interface when it asks for one?

Get IP address on RaspberryPi 4 running Yocto image

I used bitbake to generate a Linux image for my raspberry pi 4 board following the instructions provided in the meta-raspberrypi layer (https://github.com/agherzan/meta-raspberrypi). I am able to connect to my board using an FTDI USB to UART cable and running minicom on my host machine. However, I need to transfer files to my board using SCP. For that, I need the IP address and when I execute "ip a" command in my RPi4 board, I get the output below showing no IP address that I can use. Can you please provide some guidance? Do I need to add something to my conf or bblayers files?
root#raspberrypi4-64:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq qlen 1000
link/ether dc:a6:32:57:bb:1f brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether dc:a6:32:57:bb:21 brd ff:ff:ff:ff:ff:ff
Since RaspberryPi 4 has both Ethernet and WiFi interfaces available, you can connect to a network using one or the other (or both).
If you have a cable connected to your Ethernet port, you just need to request a DHCP lease. You should be able to do that by running udhcpc -i eth0. If udhcpc command is not available, you'll need to find the recipe providing it (might be hidden in a Busybox configuration file though) or add any other DHCP client to your image.
If you plan to connect to your network over WiFi, you need first to connect to the network and then request a DHCP lease. The former can be done with wpa_supplicant, connman, nmcli, etc. They probably aren't available in your image so you would need to add one first. To connect with wpa_supplicant, do the following: wpa_passphrase "<SSID>" > wpa.conf replacing <SSID> with the SSID (name) of the network you want to connect to. It'll then wait for you to input the password of this network. Then, run wpa_supplicant -iwlan0 -cwpa.conf&. This will start a connection in background. If the connection is successful in the logs, you can continue. Then, run udhcpc -iwlan0 to get a DHCP lease and then you're good to go!
If there are no DHCP server on your network (direct connection to your host machine for example), you need to assign an IP address manually with e.g.: ip addr add <IP addr> dev <iface> replacing <IP addr> with a valid (in the same subnet as the other computer(s) in the network) IP address (and maybe subnet after it? e.g. 192.168.1.153/24) and <iface> with eth0 or wlan0.

Know CentOS7 IP address [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I just installed CentOS on my VM, I want to know his IP address to be able to connect.
When I'm doing ip addr:
I get this:
[root#localhost]# ip addr
1: lo: <LOOPBACK, UP, LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 42:01:0a:f0:7e:a4 brd ff:ff:ff:ff:ff:ff
My IP address is not displayed.
You can use
make sure your system connect with network
# ip address show
OR SIMPLY
# ip a s
However, it is still possible to use the old-fashioned ifconfig command. Thus our objective is to install ifconfig on CentOS 7 Linux which is a part of net-tools package.

Configure multicast group address on CentOs, and set multi devices to join this group address

all, i have 3 computers hosted on the same LAN with CentOs 6.5 OS installed, and i want to configure a specific Multicast Group IP address for own purpose, rather than the default 224.0.0.1; then add the all computers NIC to the group address. Anyone could tell me how to configure it? the hosts basic configuration is as below:
# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:4B:B6:29
inet addr:192.168.2.5 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4b:b629/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
# cat config-2.6.32-504.30.3.el6.x86_64|grep MULTICAST
CONFIG_IP_MULTICAST=y
Thanks in advance and looking forward your help.

setup xen on two phisical interfaces

does anybody know how to setup XEN to use 2 interfaces? I have a subnet of local IPs on eth0 and subnet of external IPs on eth1. I want containers to be as on a dom0: eth0 and eth1 routed respectivly.
Thanks in advance
I'm currently using two NIC interfaces with Xenserver 6.2. I created them using XenCenter, I'm doing exactly what you're asking, using eth0 on all VMS for local connections and eth1 for internet.
How to do it.
If you have the pool created you need to go to the Networking tab, there you can add a network using the "Add Network" button and then follow the wizard.
If you have any more questions, there is a guide from Citrix. http://support.citrix.com/servlet/KbServlet/download/34969-102-704897/reference.pdf
Good luck.
I found solution by myself. I'll discribe it in case of someone need it
So far I had eth0 interface and br0 configured.
On dom0 I add additinal bridge. I call it br1
addbr addbr br1
Then I bind it to physical interface eth1
addif br1 eth1
Next, I am on Debaian, I configure /etc/network as follows
# The loopback network interface
auto lo
iface lo inet loopback
The primary network interface
auto br0
iface br0 inet static
address 172.16.15.240
netmask 255.255.255.0
network 172.16.15.0
gateway 172.16.15.1
broadcast 172.16.15.255
bridge_ports eth0
bridge_stp on
bridge_maxwait 0
bridge_fd 0
auto br1
iface br1 inet static
address 91.135.xxx.xxx
netmask 255.255.255.240
network 91.135.xxx.xxx
broadcast 91.135.xxx.xxx
gateway 91.135.xxx.xxx
bridge_ports eth1
bridge_stp on
bridge_maxwait 0
bridge_fd 0
dns-nameservers 8.8.8.8
Then in config file for container add virtual interface as follows
vif = [ 'ip=172.16.15.243 ,mac=00:16:3E:18:AF:C3,bridge=br0',
'ip=91.135.xxx.xxx ,mac=00:16:3E:DD:2D:00,bridge=br1'
]
That's it. After reboot both dom0 and domN, you will have container connected to phisical interfaces