[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

network loopback based kernle module and ping - calrification question



Hello,

I had tried the following little module , which is based on
linux kernel loopback device. The module name is nic.
I run:
insmdo nic.ko
and it was loaded.

What I do is also create a file named: /etc/sysconfig/network-scripts/ifcfg-nic
and ran ifup nic up;

The ifcfg-nic file is:
DEVICE=nic
IPADDR=127.0.0.2
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=nicloopback

when I ran:
"ifconfig -a"
I saw:
nic       Link encap:AMPR NET/ROM  HWaddr
         inet addr:127.0.0.2  Mask:255.0.0.0
         UP RUNNING  MTU:0  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)

Now what I do not understand is:
when I ran
ping 127.0.0.2
I got:
PING 127.0.0.2 (127.0.0.2) 56(84) bytes of data.
64 bytes from 127.0.0.2: icmp_seq=1 ttl=64 time=0.046 ms
64 bytes from 127.0.0.2: icmp_seq=2 ttl=64 time=0.040 ms

who does answer me ? there is no handling of recieve interrupts in that module.
What causes the packet which is sent to 127.0.0.2 to give this answer ?
where is this mechanism implemented in the kernel ?

Here is the code:


static int nic_xmit(struct sk_buff *skb, struct net_device *dev) { printk("in nic_xmit\n"); return 0; }


struct net_device nic_device = { .name = "nic", .get_stats = NULL, .priv = NULL, .hard_start_xmit = nic_xmit, };

static int __init nic_init(void)
	{
	register_netdev(&nic_device);
	return 0;	
	}

//////////////////////////////////////////////////////////////////////////////

static void __exit nic_exit(void)
	{
	unregister_netdev(&nic_device);
	}

	
//////////////////////////////////////////////////////////////////////////////

module_init(nic_init)
module_exit(nic_exit)


MODULE_DESCRIPTION("test"); MODULE_LICENSE("GPL");

Regards,
Mark

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ