Forums » Software Development »
Sending/Receiving Raw Ethernet Packets
Added by Richard Joyce over 12 years ago
I am trying to write a Linux application for my MityArm 335x Dev board to send and receive raw Ethernet packets to/from a custom embedded board of our design. Our custom embedded board already successfully communicates with other boards and a PC using raw Ethernet packets (none of them running Linux).
I am a novice Linux user/developer and I have been following examples online on how to open a raw socket, bind the socket to a interface and then send/receive the raw packets. I have been able to use WireShark to verify that I am able to send out a raw packet from the MityArm dev board, but it appears that all the raw packets sent to the dev board are being dropped. But my application does show that other broadcast packets out on the network do get through and I can read them.
Below is an example of the dev board hooked directly to our custom board. You can see that a link is made and Rx Packets are tallied, but 100% are dropped. Many online examples of using raw Ethernet packets indicate the port needs to be in promiscuous mode. But when I try to set promiscuous mode, I get the error below. I believe this had to do with the built in 3 port switch, but I am having trouble finding documentation on this switch and how to configure it. Our custom board is just using a broadcast Ethernet MAC address to try to communicate. I do see other broadcast messages get through when I hook the dev board up to our network, so I am wondering why these messages from our board are not getting through. The packets from our custom board do use a set VLAN id. Would that be causing the switch/Linux to drop them?
Thanks,
Richard Joyce
root@mityarm-335x:~# ifconfig
eth0 Link encap:Ethernet HWaddr D4:94:A1:87:01:7A
UP BROADCAST ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:40
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
root@mityarm-335x:~# [ 129.722117] PHY: 0:01 - Link is Up - 100/Full
root@mityarm-335x:~# ifconfig eth0
eth0 Link encap:Ethernet HWaddr D4:94:A1:87:01:7A
UP BROADCAST RUNNING ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:30 errors:0 dropped:30 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1920 (1.8 KiB) TX bytes:1180 (1.1 KiB)
Interrupt:40
root@mityarm-335x:~# ifconfig eth0
eth0 Link encap:Ethernet HWaddr D4:94:A1:87:01:7A
UP BROADCAST RUNNING ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:42 errors:0 dropped:42 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2688 (2.6 KiB) TX bytes:1180 (1.1 KiB)
Interrupt:40
root@mityarm-335x:~# [ 155.722110] PHY: 0:01 - Link is Down
root@mityarm-335x:~# ifconfig eth0 promisc
[ 166.657241] device eth0 entered promiscuous mode
[ 166.662187] net eth0: promiscuity ignored!
root@mityarm-335x:~#
Replies (9)
RE: Sending/Receiving Raw Ethernet Packets - Added by Tim Iskander over 12 years ago
Have you set the protocol number correctly, both in the packet and on the linux (335x in this case) machine? If the IPv4 stack cannot match the protocol # it will drop it (I believe).
see http://linux.die.net/man/7/raw
cheers
/Tim
RE: Sending/Receiving Raw Ethernet Packets - Added by Richard Joyce over 12 years ago
I may not be understanding correctly, but the page you sent is talking about IPv4 raw sockets. Using the protocol IPROTO_RAW. I am trying to communicate only on the Ethernet layer. I am not filling in an IP address. I am only using the MAC addresses. Here is page that is pretty close to what I am trying to do: http://aschauf.landshut.org/fh/linux/udp_vs_raw/ch01s03.html
I am using the protocol ETH_P_ALL. I think this is why I need the eth port in promiscuous mode, but the switch code will not allow it. So I'm not sure if it's Linux or the switch that is dropping the packets.
Thanks,
Richard
RE: Sending/Receiving Raw Ethernet Packets - Added by Richard Joyce over 12 years ago
Here would be another good place to look at what I'm trying to accomplish:
http://linux.die.net/man/7/packet
Richard
RE: Sending/Receiving Raw Ethernet Packets - Added by Tim Iskander over 12 years ago
Ah-ha ... I see I was layer too high!
The good news is I think you are correct about promiscuous mode...
The bad news is (from drivers/net/cpsw.c - The AM335X ethernet switch driver)
static void cpsw_ndo_change_rx_flags(struct net_device *ndev, int flags) { /* * The switch cannot operate in promiscuous mode without substantial * headache. For promiscuous mode to work, we would need to put the * ALE in bypass mode and route all traffic to the host port. * Subsequently, the host will need to operate as a "bridge", learn, * and flood as needed. For now, we simply complain here and * do nothing about it :-) */ if ((flags & IFF_PROMISC) && (ndev->flags & IFF_PROMISC)) dev_err(&ndev->dev, "promiscuity ignored!\n"); /* * The switch cannot filter multicast traffic unless it is configured * in "VLAN Aware" mode. Unfortunately, VLAN awareness requires a * whole bunch of additional logic that this driver does not implement * at present. */ if ((flags & IFF_ALLMULTI) && !(ndev->flags & IFF_ALLMULTI)) dev_err(&ndev->dev, "multicast traffic cannot be filtered!\n"); }
RE: Sending/Receiving Raw Ethernet Packets - Added by Michael Williamson over 12 years ago
You might try posting to the TI E2E site and seeing if they plan on supporting it, or if that have any work-arounds or pointers to how one might accomplish the promiscuous mode or capturing the raw packets.
Critical Link might be able to implement the functionality you need, but you should speak with Tom Catalino or Omar Rahim to determine how to facilitate that.
Thanks.
-Mike
RE: Sending/Receiving Raw Ethernet Packets - Added by Richard Joyce about 12 years ago
I found this thread on the TI E2E site:
http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/716/p/128635/615970.aspx#615970
Looks like putting the switch in bypass mode should accomplish what I need to support promiscuous mode. But I did that, and I'm still having problems seeing the packets from our custom board. I see other packets from out on the network, so I don't think there is anything wrong with my read function. And I don't think the switch is dropping the packets because changing some switch settings changed the Rx statistics reported by ifconfig. So it seems that Linux is dropping all the packets from the custom board. Since I do see the packets from the custom board on my Windows PC running WireShark, I was hoping you would know a way to run WireShark or TShark on the development board. Have you ever tried that?
Right now I'm trying to compile in the pcap library to capture packets, since that is what WireShark uses. But I am getting compile errors. I tried sudo apt-get install libpcap-dev and downloaded, build and installed the latest pcap library source, but still get errors. Have you ever tried working with the pcap library? It seems it might not be compatible with the linker. Here is the error:
/usr/local/ti-sdk-am335x-evm-05.03.02.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/bin/ld: skipping incompatible /usr/lib/libpcap.so when searching for -lpcap
/usr/local/ti-sdk-am335x-evm-05.03.02.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/bin/ld: skipping incompatible /usr/lib/libpcap.a when searching for -lpcap
/usr/local/ti-sdk-am335x-evm-05.03.02.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/bin/ld: cannot find -lpcap
I'm running out of ideas and not making any progress, so any help or ideas to try would be great.
Thanks,
Richard
RE: Sending/Receiving Raw Ethernet Packets - Added by Tim Iskander about 12 years ago
Richard
The linker error you have looks like the configure was not set up for cross compiling completely (i.e. /usr/lib/... libraries are being looked at instead of /usr/local/ti-sdk... ). I have not built libpcap or tcpdump myself so I don't know the exact incantation, but its probably along the lines of
> . /usr/local/ti-sdk-am335x-evm-05.03.02.00/linux-devkit/environment-setup > ./configure --host=i686 > make
But the good news is, there is a prebuild tcpdump package for the 335x.
root@am335x-evm:~# opkg update root@am335x-evm:~# opkg install tcpdump
Hope this helps...
cheers
/Tim
RE: Sending/Receiving Raw Ethernet Packets - Added by Richard Joyce about 12 years ago
I am still unable to build the pcap library into my application. Actually, I don't see the pcap libraries under /usr/local/ti-sdk... like I do under /usr/lib.... But for now, this should be OK. I don't think I will need pcap for my application because I found my problem. When I opened the socket, I used the protocol ETH_P_ALL, but when the socket was bound to eth0, the protocol changed to ETH_P_IP. That is why I could see packets off the network, but not from my board. So when I bind with ETH_P_ALL, I would see packets from the custom board.
Luckily, tcpdump was already installed on my dev board. Here is the output from opkg update:
root@mityarm-335x:~# opkg update
Package angstrom-version version 1:2009.11-r2.3 has no valid architecture, ignoring.
Package base-files-dbg version 3.0.14-r89.3 has no valid architecture, ignoring.
Package base-files-doc version 3.0.14-r89.3 has no valid architecture, ignoring.
Package base-files version 3.0.14-r89.3 has no valid architecture, ignoring.
Package sysvinit-inittab version 2.86-r48.3 has no valid architecture, ignoring.
Downloading http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/base/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Downloading http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/debug/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Downloading http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/gstreamer/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Downloading http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/perl/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Downloading http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/python/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Downloading http://feeds.arago-project.org/feeds/live/ipk/armv5te/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Downloading http://feeds.arago-project.org/feeds/live/ipk/arago/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Downloading http://feeds.arago-project.org/feeds/live/ipk/all/Packages.gz.
wget: server returned error: HTTP/1.0 401 Unauthorized
Collected errors:
* opkg_download: Failed to download http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/base/Packages.gz, wget returned 1.
* opkg_download: Failed to download http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/debug/Packages.gz, wget returned 1.
* opkg_download: Failed to download http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/gstreamer/Packages.gz, wget returned 1.
* opkg_download: Failed to download http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/perl/Packages.gz, wget returned 1.
* opkg_download: Failed to download http://feeds.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/python/Packages.gz, wget returned 1.
* opkg_download: Failed to download http://feeds.arago-project.org/feeds/live/ipk/armv5te/Packages.gz, wget returned 1.
* opkg_download: Failed to download http://feeds.arago-project.org/feeds/live/ipk/arago/Packages.gz, wget returned 1.
* opkg_download: Failed to download http://feeds.arago-project.org/feeds/live/ipk/all/Packages.gz, wget returned 1.
root@mityarm-335x:~#
But using tcpdump, I would see all packets from my custom board - VLAN tagged and untagged. tcpdump would report that some packets are dropped by interface. My application is seeing all the packets that tcpdump is reporting except for the VLAN tagged packets. So, I'm assuming these are the packets being dropped by the interface. I'm also assuming that these packets are being dropped because eth0 is not part of that VLAN. So, I would like to setup eth0 on that VLAN. From what I can find online, I need the vconfig command and 802.1Q VLAN support. I have run the menuconfig and enabled 802.1Q VLAN support under networking options and rebuilt the kernel. But I still don't see the vconfig command. What do I need to do to setup VLANs?
Thanks,
Richard
RE: Sending/Receiving Raw Ethernet Packets - Added by Richard Joyce about 12 years ago
Actually I do see the vconfig command, but when I try to execute the command, I get the error:
vconfig: can't open '/proc/net/vlan/config': No such file or directory
And this is with 802.1Q VLAN support enabled for the kernel build. I'm not sure what to do.
Thanks again,
Richard