Hi Bjørn,<br><br><br>I have put some debug message in kernel...while compilation so that we get what the error is.<br><pre class="done" id="8a/9f/6707bcde2eb6803302e0e7d2e964f0937a0c_3/1000"><font size="4"><a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1752" id="L1752" class="line" name="L1752">1752</a>static int <a href="http://lxr.linux.no/linux+*/+code=packet_bind" class="sref">packet_bind</a>(struct <a href="http://lxr.linux.no/linux+*/+code=socket" class="sref">socket</a> *<a href="http://lxr.linux.no/linux+*/+code=sock" class="sref">sock</a>, struct <a href="http://lxr.linux.no/linux+*/+code=sockaddr" class="sref">sockaddr</a> *<a href="http://lxr.linux.no/linux+*/+code=uaddr" class="sref">uaddr</a>, int <a href="http://lxr.linux.no/linux+*/+code=addr_len" class="sref">addr_len</a>)
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1753" id="L1753" class="line" name="L1753">1753</a>{
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1754" id="L1754" class="line" name="L1754">1754</a>        struct <a href="http://lxr.linux.no/linux+*/+code=sockaddr_ll" class="sref">sockaddr_ll</a> *<a href="http://lxr.linux.no/linux+*/+code=sll" class="sref">sll</a> = (struct <a href="http://lxr.linux.no/linux+*/+code=sockaddr_ll" class="sref">sockaddr_ll</a> *)<a href="http://lxr.linux.no/linux+*/+code=uaddr" class="sref">uaddr</a>;
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1755" id="L1755" class="line" name="L1755">1755</a>        struct <a href="http://lxr.linux.no/linux+*/+code=sock" class="sref">sock</a> *<a href="http://lxr.linux.no/linux+*/+code=sk" class="sref">sk</a> = <a href="http://lxr.linux.no/linux+*/+code=sock" class="sref">sock</a>-><a href="http://lxr.linux.no/linux+*/+code=sk" class="sref">sk</a>;
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1756" id="L1756" class="line" name="L1756">1756</a>        struct <a href="http://lxr.linux.no/linux+*/+code=net_device" class="sref">net_device</a> *<a href="http://lxr.linux.no/linux+*/+code=dev" class="sref">dev</a> = <a href="http://lxr.linux.no/linux+*/+code=NULL" class="sref">NULL</a>;
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1757" id="L1757" class="line" name="L1757">1757</a>        int <a href="http://lxr.linux.no/linux+*/+code=err" class="sref">err</a>;
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1758" id="L1758" class="line" name="L1758">1758</a>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1759" id="L1759" class="line" name="L1759">1759</a>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1760" id="L1760" class="line" name="L1760">1760</a>        <span class="comment">/*</span>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1761" id="L1761" class="line" name="L1761">1761</a><span class="comment">         *      Check legality</span>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1762" id="L1762" class="line" name="L1762">1762</a><span class="comment">         */</span>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1763" id="L1763" class="line" name="L1763">1763</a>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1764" id="L1764" class="line" name="L1764">1764</a>        if (<a href="http://lxr.linux.no/linux+*/+code=addr_len" class="sref">addr_len</a> < sizeof(struct <a href="http://lxr.linux.no/linux+*/+code=sockaddr_ll" class="sref">sockaddr_ll</a>))<br>

              {<br>                   printk("packet_bind: invalid len %d %d\n", addr_len, sizeof(struct sockaddr_ll));<br>                    </font><font size="4"> ///ADDED THIS PRINTK IN LINUX CODE<br></font><font size="4"><a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1765" id="L1765" class="line" name="L1765">1765</a>               return -<a href="http://lxr.linux.no/linux+*/+code=EINVAL" class="sref">EINVAL</a>;<br>

              }<br> <a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1766" id="L1766" class="line" name="L1766">1766</a>        if (<a href="http://lxr.linux.no/linux+*/+code=sll" class="sref">sll</a>-><a href="http://lxr.linux.no/linux+*/+code=sll_family" class="sref">sll_family</a> != <a href="http://lxr.linux.no/linux+*/+code=AF_PACKET" class="sref">AF_PACKET</a>)<br>

               {<br>                     printk("packet_bind: invalid socket family %d %d\n", sll->sll_family,  AF_PACKET);  <br>                   ///ADDED THIS PRINTK IN LINUX CODE<br> <a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1767" id="L1767" class="line" name="L1767">1767</a>                return -<a href="http://lxr.linux.no/linux+*/+code=EINVAL" class="sref">EINVAL</a>;<br>

               } <br><br><a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1768" id="L1768" class="line" name="L1768">1768</a>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1769" id="L1769" class="line" name="L1769">1769</a>        if (<a href="http://lxr.linux.no/linux+*/+code=sll" class="sref">sll</a>-><a href="http://lxr.linux.no/linux+*/+code=sll_ifindex" class="sref">sll_ifindex</a>) {
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1770" id="L1770" class="line" name="L1770">1770</a>                <a href="http://lxr.linux.no/linux+*/+code=err" class="sref">err</a> = -<a href="http://lxr.linux.no/linux+*/+code=ENODEV" class="sref">ENODEV</a>;
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1771" id="L1771" class="line" name="L1771">1771</a>                <a href="http://lxr.linux.no/linux+*/+code=dev" class="sref">dev</a> = <a href="http://lxr.linux.no/linux+*/+code=dev_get_by_index" class="sref">dev_get_by_index</a>(<a href="http://lxr.linux.no/linux+*/+code=sock_net" class="sref">sock_net</a>(<a href="http://lxr.linux.no/linux+*/+code=sk" class="sref">sk</a>), <a href="http://lxr.linux.no/linux+*/+code=sll" class="sref">sll</a>-><a href="http://lxr.linux.no/linux+*/+code=sll_ifindex" class="sref">sll_ifindex</a>);
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1772" id="L1772" class="line" name="L1772">1772</a>                if (<a href="http://lxr.linux.no/linux+*/+code=dev" class="sref">dev</a> == <a href="http://lxr.linux.no/linux+*/+code=NULL" class="sref">NULL</a>)
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1773" id="L1773" class="line" name="L1773">1773</a>                        goto <a href="http://lxr.linux.no/linux+*/+code=out" class="sref">out</a>;
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1774" id="L1774" class="line" name="L1774">1774</a>        }
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1775" id="L1775" class="line" name="L1775">1775</a>        <a href="http://lxr.linux.no/linux+*/+code=err" class="sref">err</a> = <a href="http://lxr.linux.no/linux+*/+code=packet_do_bind" class="sref">packet_do_bind</a>(<a href="http://lxr.linux.no/linux+*/+code=sk" class="sref">sk</a>, <a href="http://lxr.linux.no/linux+*/+code=dev" class="sref">dev</a>, <a href="http://lxr.linux.no/linux+*/+code=sll" class="sref">sll</a>-><a href="http://lxr.linux.no/linux+*/+code=sll_protocol" class="sref">sll_protocol</a> ? : <a href="http://lxr.linux.no/linux+*/+code=pkt_sk" class="sref">pkt_sk</a>(<a href="http://lxr.linux.no/linux+*/+code=sk" class="sref">sk</a>)-><a href="http://lxr.linux.no/linux+*/+code=num" class="sref">num</a>);
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1776" id="L1776" class="line" name="L1776">1776</a>
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1777" id="L1777" class="line" name="L1777">1777</a><a href="http://lxr.linux.no/linux+*/+code=out" class="sref">out</a>:
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1778" id="L1778" class="line" name="L1778">1778</a>        return <a href="http://lxr.linux.no/linux+*/+code=err" class="sref">err</a>;
<a href="http://lxr.linux.no/linux+*/net/packet/af_packet.c#L1779" id="L1779" class="line" name="L1779">1779</a>}</font></pre><br><br><br>Got the output as <br><br>Internet Systems Consortium DHCP Server 4.2.2<br>Copyright 2004-2011 Internet Systems Consortium.<br>

All rights reserved.<br>For info, please visit <a href="https://www.isc.org/software/dhcp/">https://www.isc.org/software/dhcp/</a><br>Wrote 0 leases to leases file.<br>packet_bind: invalid len 16 20<br>socket: Error_2 (Bind to the interface name) Invalid argument , 22 16- make sure<br>

CONFIG_PACKET (Packet socket) and CONFIG_FILTER<br>(Socket Filtering) are enabled in your kernel<br>configuration!<br><br>If you did not get this software from <a href="http://ftp.isc.org">ftp.isc.org</a>, please<br>get the latest from <a href="http://ftp.isc.org">ftp.isc.org</a> and install that before<br>

requesting help.<br><br>If you did get this software from <a href="http://ftp.isc.org">ftp.isc.org</a> and have not<br>yet read the README, please read it before requesting help.<br>If you intend to request help from the <a href="mailto:dhcp-server@isc.org">dhcp-server@isc.org</a><br>

mailing list, please read the section on the README about<br>submitting bug reports and requests for help.<br><br>Please do not under any circumstances send requests for<br>help directly to the authors of this software - please<br>

send them to the appropriate mailing list as described in<br>the README file.<br><br>exiting.<br><br><br>You can find this """packet_bind: invalid len 16 20 """<br><br>addr_len is 16 and size of sockaddr_ll is 20 hence its failing!!!!<br>

<br>Any pointers as to why its different? sizeof sa passed in bind is 16 whereas it has to be 20...<br><br><br>Regards,<br>Mukund<br><br><br><br><div class="gmail_quote">On Wed, Nov 30, 2011 at 3:00 PM, Bjørn Mork <span dir="ltr"><<a href="mailto:bjorn@mork.no">bjorn@mork.no</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Mukund Deshpande <<a href="mailto:sai.mukund.sagar@gmail.com">sai.mukund.sagar@gmail.com</a>> writes:<br>


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