CONFIG_FILTER error on arm
Bjørn Mork
bjorn at mork.no
Wed Nov 30 09:30:47 UTC 2011
Mukund Deshpande <sai.mukund.sagar at gmail.com> writes:
> I added extra message for each of the cases where this error was occuring.
> It has failed at bind call..
That's interesting.
> Any suggestions how to find if there is any problem in ifindex detection?
I see now that I was a bit too quick as usual when thinking about what
could fail, looking only briefly at the lines before the bind() call and
assuming that the code must be correct on most systems.
Looking at it more in detail, I now believe this code is utterly wrong
on *any* system....
Quoting from packet(7):
</quote>
NAME
packet, AF_PACKET - packet interface on device level.
SYNOPSIS
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <net/ethernet.h> /* the L2 protocols */
packet_socket = socket(AF_PACKET, int socket_type, int protocol);
DESCRIPTION
Packet sockets are used to receive or send raw packets at the device driver (OSI Layer 2) level.
They allow the user to implement protocol modules in user space on top of the physical layer.
The socket_type is either SOCK_RAW for raw packets including the link level header or SOCK_DGRAM
for cooked packets with the link level header removed. The link level header information is
available in a common format in a sockaddr_ll. protocol is the IEEE 802.3 protocol number in
network order. See the <linux/if_ether.h> include file for a list of allowed protocols. When
protocol is set to htons(ETH_P_ALL) then all protocols are received. All incoming packets of
that protocol type will be passed to the packet socket before they are passed to the protocols
implemented in the kernel.
Only processes with effective UID 0 or the CAP_NET_RAW capability may open packet sockets.
SOCK_RAW packets are passed to and from the device driver without any changes in the packet
data. When receiving a packet, the address is still parsed and passed in a standard sockaddr_ll
address structure. When transmitting a packet, the user supplied buffer should contain the
physical layer header. That packet is then queued unmodified to the network driver of the
interface defined by the destination address. Some device drivers always add other headers.
SOCK_RAW is similar to but not compatible with the obsolete AF_INET/SOCK_PACKET of Linux 2.0.
SOCK_DGRAM operates on a slightly higher level. The physical header is removed before the
packet is passed to the user. Packets sent through a SOCK_DGRAM packet socket get a suitable
physical layer header based on the information in the sockaddr_ll destination address before
they are queued.
By default all packets of the specified protocol type are passed to a packet socket. To only
get packets from a specific interface use bind(2) specifying an address in a struct sockaddr_ll
to bind the packet socket to an interface. Only the sll_protocol and the sll_ifindex address
fields are used for purposes of binding.
</quote>
So you can't really do socket(PF_PACKET, SOCK_PACKET, ...) and expect it
to work. And the bind() may be correct for the obsolete SOCK_PACKET
sockets, but I don't think it will work correctly with AF_PACKET
sockets. They need to have sll_protocol and sll_ifindex set, and not the
ifreq structure in info->ifp.
I have a feeling I must be missing something here, as this code
obviously does work for most of us. Maybe the bind() call does in fact
work, but the interface name in info->ifp is wrong somehow?
Maybe someone else has a comment?
Bjørn
More information about the dhcp-users
mailing list