netfilter.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* printk mac address --hangs
@ 2010-05-13 15:45 ratheesh k
  2010-05-13 16:19 ` Jan Engelhardt
  0 siblings, 1 reply; 8+ messages in thread
From: ratheesh k @ 2010-05-13 15:45 UTC (permalink / raw)
  To: Netfilter mailing list

Why this program cause kernel crash ? , If i comment out "memcpy " ,
it works fine


*******************************************************************************************
 #include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
# include <linux/skbuff.h>

# include <linux/ip.h>
# include <linux/tcp.h>
MODULE_LICENSE("Dual BSD/GPL");

#define NF_IP_LOCAL_OUT     3


/* This is the structure we shall use to register our function */

static struct nf_hook_ops nfho;

/* This is the hook function itself */
unsigned int hook_func(unsigned int hooknum,
                       struct sk_buff *skb,
                       const struct net_device *in,
                       const struct net_device *out,
                       int (*okfn)(struct sk_buff *))
{
    struct iphdr* ip_header;
    struct tcphdr* tcp_header;
    struct ethhdr * eth_header ;
    char src[ETH_ALEN+2];
    char dst[ETH_ALEN+2];
      src[ETH_ALEN+1]='\0';
      dst[ETH_ALEN+1]='\0' ;

     ip_header  = ip_hdr(skb);
    tcp_header = tcp_hdr(skb);
    eth_header = eth_hdr(skb);


      memcpy(src , eth_header->h_source , ETH_ALEN );
      memcpy(dst , eth_header->h_dest , ETH_ALEN );

    return NF_ACCEPT;           /* Drop ALL packets */
}

/* Initialisation routine */
int init_module()
{
    /* Fill in our hook structure */
    nfho.hook = hook_func;         /* Handler function */

    nfho.hooknum  = NF_IP_LOCAL_OUT; /* First hook for IPv4 */

    nfho.pf       = PF_INET;

    nfho.priority = NF_IP_PRI_FIRST;   /* Make our function first */

    nf_register_hook(&nfho);

    return 0;
}
	
/* Cleanup routine */
void cleanup_module()
{
    nf_unregister_hook(&nfho);
}
***********************************

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: printk mac address --hangs
  2010-05-13 15:45 printk mac address --hangs ratheesh k
@ 2010-05-13 16:19 ` Jan Engelhardt
  2010-05-13 17:07   ` ratheesh k
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Engelhardt @ 2010-05-13 16:19 UTC (permalink / raw)
  To: ratheesh k; +Cc: Netfilter mailing list


On Thursday 2010-05-13 17:45, ratheesh k wrote:

>Why this program cause kernel crash ? , If i comment out "memcpy " ,
>it works fine
>
>/* This is the hook function itself */
>unsigned int hook_func(unsigned int hooknum,
>                       struct sk_buff *skb,
>                       const struct net_device *in,
>                       const struct net_device *out,
>                       int (*okfn)(struct sk_buff *))
>{
>    struct iphdr* ip_header;
>    struct tcphdr* tcp_header;
>    struct ethhdr * eth_header ;
>    char src[ETH_ALEN+2];
>    char dst[ETH_ALEN+2];
>      src[ETH_ALEN+1]='\0';
>      dst[ETH_ALEN+1]='\0' ;
>
>     ip_header  = ip_hdr(skb);
>    tcp_header = tcp_hdr(skb);
>    eth_header = eth_hdr(skb);
>
>
>      memcpy(src , eth_header->h_source , ETH_ALEN );
>      memcpy(dst , eth_header->h_dest , ETH_ALEN );

If you do not have an Ethernet packet, this is going to explode.


>
>    return NF_ACCEPT;           /* Drop ALL packets */
>}
>
>/* Initialisation routine */
>int init_module()
                 ^ void

>{
>    /* Fill in our hook structure */
>    nfho.hook = hook_func;         /* Handler function */
>
>    nfho.hooknum  = NF_IP_LOCAL_OUT; /* First hook for IPv4 */
>
>    nfho.pf       = PF_INET;
>
>    nfho.priority = NF_IP_PRI_FIRST;   /* Make our function first */
>
>    nf_register_hook(&nfho);
>
>    return 0;
>}
>	
>/* Cleanup routine */
>void cleanup_module()
                     ^ void

>{
>    nf_unregister_hook(&nfho);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: printk mac address --hangs
  2010-05-13 16:19 ` Jan Engelhardt
@ 2010-05-13 17:07   ` ratheesh k
  2010-05-13 17:16     ` Jan Engelhardt
  0 siblings, 1 reply; 8+ messages in thread
From: ratheesh k @ 2010-05-13 17:07 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Netfilter mailing list

On Thu, May 13, 2010 at 9:49 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
> If you do not have an Ethernet packet, this is going to explode.

I have only one  ethernet network interface (eth0 ) with 192.168.1.5 .
I could see in wireshark all  packets with ethernet mac addresses .
When i try to prink the mac address or copy ,  it hangs ..

-Ratheesh


On Thu, May 13, 2010 at 9:49 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
>h
> On Thursday 2010-05-13 17:45, ratheesh k wrote:
>
>>Why this program cause kernel crash ? , If i comment out "memcpy " ,
>>it works fine
>>
>>/* This is the hook function itself */
>>unsigned int hook_func(unsigned int hooknum,
>>                       struct sk_buff *skb,
>>                       const struct net_device *in,
>>                       const struct net_device *out,
>>                       int (*okfn)(struct sk_buff *))
>>{
>>    struct iphdr* ip_header;
>>    struct tcphdr* tcp_header;
>>    struct ethhdr * eth_header ;
>>    char src[ETH_ALEN+2];
>>    char dst[ETH_ALEN+2];
>>      src[ETH_ALEN+1]='\0';
>>      dst[ETH_ALEN+1]='\0' ;
>>
>>     ip_header  = ip_hdr(skb);
>>    tcp_header = tcp_hdr(skb);
>>    eth_header = eth_hdr(skb);
>>
>>
>>      memcpy(src , eth_header->h_source , ETH_ALEN );
>>      memcpy(dst , eth_header->h_dest , ETH_ALEN );
>
> If you do not have an Ethernet packet, this is going to explode.
>
>
>>
>>    return NF_ACCEPT;           /* Drop ALL packets */
>>}
>>
>>/* Initialisation routine */
>>int init_module()
>                 ^ void
>
>>{
>>    /* Fill in our hook structure */
>>    nfho.hook = hook_func;         /* Handler function */
>>
>>    nfho.hooknum  = NF_IP_LOCAL_OUT; /* First hook for IPv4 */
>>
>>    nfho.pf       = PF_INET;
>>
>>    nfho.priority = NF_IP_PRI_FIRST;   /* Make our function first */
>>
>>    nf_register_hook(&nfho);
>>
>>    return 0;
>>}
>>
>>/* Cleanup routine */
>>void cleanup_module()
>                     ^ void
>
>>{
>>    nf_unregister_hook(&nfho);
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: printk mac address --hangs
  2010-05-13 17:07   ` ratheesh k
@ 2010-05-13 17:16     ` Jan Engelhardt
  2010-05-13 17:24       ` ratheesh k
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Engelhardt @ 2010-05-13 17:16 UTC (permalink / raw)
  To: ratheesh k; +Cc: Netfilter mailing list

On Thursday 2010-05-13 19:07, ratheesh k wrote:

>On Thu, May 13, 2010 at 9:49 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
>> If you do not have an Ethernet packet, this is going to explode.
>
>I have only one  ethernet network interface (eth0 ) with 192.168.1.5 .
>I could see in wireshark all  packets with ethernet mac addresses .
>When i try to prink the mac address or copy ,  it hangs ..

Your hook received packets from all interfaces, including lo and 
ethhdr-less tunnels.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: printk mac address --hangs
  2010-05-13 17:16     ` Jan Engelhardt
@ 2010-05-13 17:24       ` ratheesh k
  2010-05-13 19:26         ` Jan Engelhardt
  0 siblings, 1 reply; 8+ messages in thread
From: ratheesh k @ 2010-05-13 17:24 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Netfilter mailing list

On Thu, May 13, 2010 at 10:46 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
> Your hook received packets from all interfaces, including lo and
> ethhdr-less tunnels.

Packets from lo will hit NF_IP_LOCAL_OUT hook  ?
Could you please  tell  example for ether less packet  ?

Thanks,
Ratheesh .



On Thu, May 13, 2010 at 10:46 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
> On Thursday 2010-05-13 19:07, ratheesh k wrote:
>
>>On Thu, May 13, 2010 at 9:49 PM, an Engelhardt <jengelh@medozas.de> wrote:
>>> If you do not have an Ethernet packet, this is going to explode.
>>
>>I have only one  ethernet network interface (eth0 ) with 192.168.1.5 .
>>I could see in wireshark all  packets with ethernet mac addresses .
>>When i try to prink the mac address or copy ,  it hangs ..
>
> Your hook received packets from all interfaces, including lo and
> ethhdr-less tunnels.
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: printk mac address --hangs
  2010-05-13 17:24       ` ratheesh k
@ 2010-05-13 19:26         ` Jan Engelhardt
  2010-05-14  2:37           ` ratheesh k
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Engelhardt @ 2010-05-13 19:26 UTC (permalink / raw)
  To: ratheesh k; +Cc: Netfilter mailing list

On Thursday 2010-05-13 19:24, ratheesh k wrote:

>On Thu, May 13, 2010 at 10:46 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
>> Your hook received packets from all interfaces, including lo and
>> ethhdr-less tunnels.
>
>Packets from lo will hit NF_IP_LOCAL_OUT hook  ?

Clearly.

>Could you please  tell  example for ether less packet  ?

As I said, all links that do not are of "ether" type (see `ip list`)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: printk mac address --hangs
  2010-05-13 19:26         ` Jan Engelhardt
@ 2010-05-14  2:37           ` ratheesh k
  2010-05-14  3:41             ` ratheesh k
  0 siblings, 1 reply; 8+ messages in thread
From: ratheesh k @ 2010-05-14  2:37 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Netfilter mailing list

On Fri, May 14, 2010 at 12:56 AM, Jan Engelhardt <jengelh@medozas.de> wrote:
>>Packets from lo will hit NF_IP_LOCAL_OUT hook  ?
>
> Clearly.

Could you please explain a little about the traversal of a local
packet . say if i do : ping 127.0.0.1 .? what are the chains/hooks  it
will hit ?

Is there any API to check whether it is a ether packet or not ?
Thanks,
Ratheesh

On Fri, May 14, 2010 at 12:56 AM, Jan Engelhardt <jengelh@medozas.de> wrote:
> On Thursday 2010-05-13 19:24, ratheesh k wrote:
>
>>On Thu, May 13, 2010 at 10:46 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
>>> Your hook received packets from all interfaces, including lo and
>>> ethhdr-less tunnels.
>>
>>Packets from lo will hit NF_IP_LOCAL_OUT hook  ?
>
> Clearly.
>
>>Could you please  tell  example for ether less packet  ?
>
> As I said, all links that do not are of "ether" type (see `ip list`)
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: printk mac address --hangs
  2010-05-14  2:37           ` ratheesh k
@ 2010-05-14  3:41             ` ratheesh k
  0 siblings, 0 replies; 8+ messages in thread
From: ratheesh k @ 2010-05-14  3:41 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Netfilter mailing list

On Fri, May 14, 2010 at 8:07 AM, ratheesh k <ratheesh.ksz@gmail.com> wrote:
> On Fri, May 14, 2010 at 12:56 AM, Jan Engelhardt <jengelh@medozas.de> wrote:
>>>Packets from lo will hit NF_IP_LOCAL_OUT hook  ?
>>
>> Clearly.
>
> Could you please explain a little about the traversal of a local
> packet . say if i do : ping 127.0.0.1 .? what are the chains/hooks  it
> will hit ?
>
> Is there any API to check whether it is a ether packet or not ?
> Thanks,
> Ratheesh
>
> On Fri, May 14, 2010 at 12:56 AM, Jan Engelhardt <jengelh@medozas.de> wrote:
>> On Thursday 2010-05-13 19:24, ratheesh k wrote:
>>
>>>On Thu, May 13, 2010 at 10:46 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
>>>> Your hook received packets from all interfaces, including lo and
>>>> ethhdr-less tunnels.
>>>
>>>Packets from lo will hit NF_IP_LOCAL_OUT hook  ?
>>
>> Clearly.
>>
>>>Could you please  tell  example for ether less packet  ?
>>
>> As I said, all links that do not are of "ether" type (see `ip list`)
>>
>

OK , lo packet will hit INPUT and OUTPUT . loop packet wont have ether
header ?>
Is there any API to check whether it is a ether packet or not ?

Thanks,
Ratheesh

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-05-14  3:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-13 15:45 printk mac address --hangs ratheesh k
2010-05-13 16:19 ` Jan Engelhardt
2010-05-13 17:07   ` ratheesh k
2010-05-13 17:16     ` Jan Engelhardt
2010-05-13 17:24       ` ratheesh k
2010-05-13 19:26         ` Jan Engelhardt
2010-05-14  2:37           ` ratheesh k
2010-05-14  3:41             ` ratheesh k

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).