LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-27-2017, 11:30 AM   #1
SAGARSINGHA
LQ Newbie
 
Registered: Aug 2016
Posts: 12

Rep: Reputation: Disabled
Network connection is going down after some packet is received in rx_handler


Hi,
I am using one VM. Here I have written one simple module (actually for L2 forwarding but for time being for testing purpose to check is the all packets are reeving in the handler or not )which will steal the packet.

The code is as below:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/skbuff.h>
#include <linux/if_packet.h>
#include <linux/ip.h>
#include <linux/netdevice.h>
#include <uapi/linux/if_ether.h>
#include <linux/if_ether.h>
#include <linux/rtnetlink.h>//for rtnl_lock() and rtnl_unlock()
#define NR_DEV 3


rx_handler_result_t sagar_rx_handler(struct sk_buff **);
void dev_cache(void);
void register_device_handler(struct net_device *);


char *port_map_dev[NR_DEV] = {"ens160"};

typedef struct dev_map
{
struct net_device *in_dev;
struct net_device *out_dev;

}dev_map;

typedef struct dev_details
{
struct net_device *dev;
char ifname[IFNAMSIZ];
}dev_details;

dev_details details[NR_DEV] = {0};

dev_map map_table[NR_DEV] = {0};

rx_handler_result_t sagar_rx_handler(struct sk_buff **pskb)
{
struct sk_buff *my_skb = *pskb;
printk("In %s\n",__func__);


printk("DEVICE:%s\n",my_skb->dev->name);
kfree_skb(my_skb);
return 0;
}

void register_device_handler(struct net_device *dev)
{
printk("In %s DEV:%s\n",__func__,dev->name);
rtnl_lock();
if(netdev_rx_handler_register(dev,sagar_rx_handler,NULL))
{
printk("netdev_rx_handler_register failed\n");
}
rtnl_unlock();
}
void dev_cache(void)
{
struct net_device *dev = NULL;
int i = 0;
for_each_netdev(&init_net,dev)
{
details[dev->ifindex].dev = NULL;
for(i = 0; i < NR_DEV;i++)
{
if(port_map_dev[i] && !strcmp(port_map_dev[i],dev->name))
{
printk("DEVICE:%s is registered\n",dev->name);
printk("DEV INDEX:%d is registered\n",dev->ifindex);
details[dev->ifindex].dev = dev;
strcpy(details[dev->ifindex].ifname,dev->name);
register_device_handler(dev);
}
}
}

}
void unregister_device_handler(void)
{
int i;
for(i = 0; i < NR_DEV;i++)
{
if(details[i].dev != NULL)
{
// printk("In Unregsiter\n");
rtnl_lock();
netdev_rx_handler_unregister(details[i].dev);
rtnl_unlock();
}
}
}

static int __init sagar_init(void)
{
dev_cache();
printk(KERN_INFO "sagar : Module insertion completed successfully!\n");
return 0;
}

static void __exit sagar_cleanup(void)
{

unregister_device_handler();
printk(KERN_INFO "sagar : Cleaning up module....\n");
}


============PROBLEM=======================
I am running tail -f /var/log/syslog to check the log
So the problem I am facing is After inserting the module after receiving some initial packet(8-9 packet) the VM is going down mean the network connection is going down.But there is no Crash have seen from the /var/log/syslog

========Below is the log============
Aug 27 19:55:01 ctuser-virtual-machine CRON[5184]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Aug 27 19:58:29 ctuser-virtual-machine systemd[1]: Started Session 372 of user ctuser.
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512109] driver_skel: loading out-of-tree module taints kernel.
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512166] driver_skel: module verification failed: signature and/or required key missing - tainting kernel
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512502] DEVICE:ens160 is registered
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512503] DEV INDEX:2 is registered
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512503] In register_device_handler DEV:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512506] sagar : Module insertion completed successfully!
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.531822] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.531823] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.555102] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.555107] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.614526] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.614530] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.651453] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.651457] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.670905] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.670909] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.690207] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.690212] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.709182] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.709187] DEVICE:ens160


What may be the problem!!Please help me here.

Thanks!!

Last edited by SAGARSINGHA; 08-27-2017 at 11:33 AM.
 
Old 08-27-2017, 11:54 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,281

Rep: Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897
Quote:
Originally Posted by SAGARSINGHA View Post
Hi,
I am using one VM. Here I have written one simple module (actually for L2 forwarding but for time being for testing purpose to check is the all packets are reeving in the handler or not )which will steal the packet. The code is as below:
Code:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/skbuff.h>
#include <linux/if_packet.h>
#include <linux/ip.h>
#include <linux/netdevice.h>
#include <uapi/linux/if_ether.h>
#include <linux/if_ether.h>
#include <linux/rtnetlink.h>//for rtnl_lock() and rtnl_unlock()
#define NR_DEV  3


rx_handler_result_t sagar_rx_handler(struct sk_buff **);
void dev_cache(void);
void register_device_handler(struct net_device *);


char *port_map_dev[NR_DEV] = {"ens160"};

typedef struct dev_map
{
        struct net_device *in_dev;
        struct net_device *out_dev;

}dev_map;

typedef struct dev_details
{
        struct net_device *dev;
        char ifname[IFNAMSIZ];
}dev_details;

dev_details details[NR_DEV] = {0};

dev_map map_table[NR_DEV] = {0};

rx_handler_result_t sagar_rx_handler(struct sk_buff **pskb)
{
        struct sk_buff *my_skb = *pskb;
        printk("In %s\n",__func__);


        printk("DEVICE:%s\n",my_skb->dev->name);
    kfree_skb(my_skb);
    return 0;
}

void register_device_handler(struct net_device *dev)
{
        printk("In %s DEV:%s\n",__func__,dev->name);
                rtnl_lock();
                if(netdev_rx_handler_register(dev,sagar_rx_handler,NULL))
                {
                        printk("netdev_rx_handler_register failed\n");
                }
                rtnl_unlock();
}
void dev_cache(void)
{
        struct net_device *dev = NULL;
        int i = 0;
        for_each_netdev(&init_net,dev)
        {
                details[dev->ifindex].dev = NULL;
                for(i = 0; i < NR_DEV;i++)
                {
                if(port_map_dev[i] && !strcmp(port_map_dev[i],dev->name))
                {
                printk("DEVICE:%s is registered\n",dev->name);
                printk("DEV INDEX:%d is registered\n",dev->ifindex);
                details[dev->ifindex].dev = dev;
                strcpy(details[dev->ifindex].ifname,dev->name);
                register_device_handler(dev);
                }
        }
        }

}
void unregister_device_handler(void)
{
        int i;
        for(i = 0; i < NR_DEV;i++)
        {
        if(details[i].dev != NULL)
        {
//      printk("In Unregsiter\n");
        rtnl_lock();
        netdev_rx_handler_unregister(details[i].dev);
        rtnl_unlock();
        }
        }
}

static int __init sagar_init(void)
{
dev_cache();
printk(KERN_INFO "sagar : Module insertion completed successfully!\n");
 return 0;
}

static void __exit sagar_cleanup(void)
{

 unregister_device_handler();
 printk(KERN_INFO "sagar : Cleaning up module....\n");
}
============PROBLEM=======================
I am running tail -f /var/log/syslog to check the log
So the problem I am facing is After inserting the module after receiving some initial packet(8-9 packet) the VM is going down mean the network connection is going down.But there is no Crash have seen from the /var/log/syslog
========Below is the log============
Code:
Aug 27 19:55:01 ctuser-virtual-machine CRON[5184]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Aug 27 19:58:29 ctuser-virtual-machine systemd[1]: Started Session 372 of user ctuser.
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512109] driver_skel: loading out-of-tree module taints kernel.
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512166] driver_skel: module verification failed: signature and/or required key missing - tainting kernel
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512502] DEVICE:ens160 is registered
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512503] DEV INDEX:2 is registered
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512503] In register_device_handler DEV:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.512506] sagar : Module insertion completed successfully!
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.531822] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.531823] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.555102] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.555107] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.614526] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.614530] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.651453] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.651457] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.670905] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.670909] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.690207] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.690212] DEVICE:ens160
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.709182] In sagar_rx_handler
Aug 27 20:02:29 ctuser-virtual-machine kernel: [181579.709187] DEVICE:ens160
What may be the problem!!Please help me here.
Please use CODE tags when posting such things...very hard to read otherwise. And based on what you posted, it's impossible to tell...you don't tell us what version/distro of Linux you're using, but your syslog shows that your module got inserted. Past that...all we can tell you is that you have a problem in your code.

Are you asking us to debug your kernel module that you wrote, for you?
 
Old 08-28-2017, 12:13 AM   #3
SAGARSINGHA
LQ Newbie
 
Registered: Aug 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Please use CODE tags when posting such things...very hard to read otherwise. And based on what you posted, it's impossible to tell...you don't tell us what version/distro of Linux you're using, but your syslog shows that your module got inserted. Past that...all we can tell you is that you have a problem in your code.

Are you asking us to debug your kernel module that you wrote, for you?
Thanks for your response!!
I am using UBUNTU16.04 of linux.
I am not able to find out the mistake I have done in code.
Simply I have register one packet handler through netdev_rx_handler_register in register_device_handler() function with a specific interface.

Please cheeck once the Code!!!
 
Old 08-28-2017, 07:38 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,281

Rep: Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897
Quote:
Originally Posted by SAGARSINGHA View Post
Thanks for your response!!
I am using UBUNTU16.04 of linux. I am not able to find out the mistake I have done in code. Simply I have register one packet handler through netdev_rx_handler_register in register_device_handler() function with a specific interface.

Please cheeck once the Code!!!
We understand what you want...but we are not going to debug your code for you.
 
Old 08-28-2017, 12:46 PM   #5
SAGARSINGHA
LQ Newbie
 
Registered: Aug 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
We understand what you want...but we are not going to debug your code for you.
Thats fine!!

I am able to receive the packet. The next thing when I am forwarding I am facing problem.

And regarding Code understanding you replied in other thread,I am have only written The code. I just want to know the other approach like DPDK or ODP type of things.

If you dont want to help thats fine!I will do it my self!!
 
Old 08-28-2017, 01:07 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,281

Rep: Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897
Quote:
Originally Posted by SAGARSINGHA View Post
Thats fine!!
I am able to receive the packet. The next thing when I am forwarding I am facing problem.
Ok...so since you wrote this code, what did you base it on? What debugging efforts have you done/tried??? Because all you've done here is post your code, and essentially ask us to debug it for you.
Quote:
And regarding Code understanding you replied in other thread,I am have only written The code. I just want to know the other approach like DPDK or ODP type of things. If you dont want to help thats fine!I will do it my self!!
We are happy to help...but we aren't going to write code for you, or debug code that you've written. If you're stuck, then show us your efforts and we will be happy to assist. And you need to read the "Question Guidelines" link in my posting signature...doing basic research first before posting should be the first thing you do. Putting "l2 forwarding c code" into Google pulls up many examples, with code and explanations. The first two:
http://dpdk.org/doc/guides/sample_ap...l_virtual.html
http://dpdk.readthedocs.io/en/v17.02...rward_cat.html
 
Old 08-29-2017, 12:23 AM   #7
SAGARSINGHA
LQ Newbie
 
Registered: Aug 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Ok...so since you wrote this code, what did you base it on? What debugging efforts have you done/tried??? Because all you've done here is post your code, and essentially ask us to debug it for you.

We are happy to help...but we aren't going to write code for you, or debug code that you've written. If you're stuck, then show us your efforts and we will be happy to assist. And you need to read the "Question Guidelines" link in my posting signature...doing basic research first before posting should be the first thing you do. Putting "l2 forwarding c code" into Google pulls up many examples, with code and explanations. The first two:
http://dpdk.org/doc/guides/sample_ap...l_virtual.html
http://dpdk.readthedocs.io/en/v17.02...rward_cat.html
I am not telling debug. Just want to know if this is any known issue for anyone.I have resolved the problem. The problem was the return value from rx_handler.Instead of RX_HANDLER_CONSUMED I have t return RX_HANDLER_PASS.

And about the code, I have already mentioned at initial phase only.Please find in below---

1.It is simply one packet handler I have registered with the help of netdev_rx_handler_register with a specific interface.
2.I am stealing packet from that interface.
3.Now I have forward the same packet (sk_buff) to the another interface.
4.So I am changing the "dev" member of sk_buf with the output interface.It is not crashing but after some time the system is going down. No packet is coming.have checked in /var/log/syslog
 
Old 08-29-2017, 07:57 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,281

Rep: Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897
Quote:
Originally Posted by SAGARSINGHA View Post
I am not telling debug. Just want to know if this is any known issue for anyone.
How would anyone else, anywhere, have a 'known issue' with code that YOU wrote for testing something?
Quote:
I have resolved the problem. The problem was the return value from rx_handler.Instead of RX_HANDLER_CONSUMED I have t return RX_HANDLER_PASS. And about the code, I have already mentioned at initial phase only.Please find in below---

1.It is simply one packet handler I have registered with the help of netdev_rx_handler_register with a specific interface.
2.I am stealing packet from that interface.
3.Now I have forward the same packet (sk_buff) to the another interface.
4.So I am changing the "dev" member of sk_buf with the output interface.It is not crashing but after some time the system is going down. No packet is coming.have checked in /var/log/syslog
 
Old 08-31-2017, 07:24 AM   #9
SAGARSINGHA
LQ Newbie
 
Registered: Aug 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
How would anyone else, anywhere, have a 'known issue' with code that YOU wrote for testing something?
I have described the scenario
 
Old 08-31-2017, 08:31 AM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,281

Rep: Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897Reputation: 7897
Quote:
Originally Posted by SAGARSINGHA View Post
I have described the scenario
Yes, you have repeatedly described the scenario. But again, if this is code that YOU WROTE, how is anyone else anywhere else, going to have 'known issues' with it?

Again: you wrote the code, so it's up to you to debug it.
 
Old 08-31-2017, 11:30 AM   #11
SAGARSINGHA
LQ Newbie
 
Registered: Aug 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Yes, you have repeatedly described the scenario. But again, if this is code that YOU WROTE, how is anyone else anywhere else, going to have 'known issues' with it?

Again: you wrote the code, so it's up to you to debug it.
sure. Thanks for your kind response. I have solved the problem.Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to listen for a specific ping packet and take an action when it is received paicito Linux - Networking 4 01-06-2014 12:08 PM
received UDP packet length sasubillis Linux - Software 1 02-12-2010 08:57 AM
Incorrect MAC received on packet, SuSE 10.2 jaguar11735 Linux - Software 5 07-11-2007 07:32 AM
problem in received packet linux_lover2005 Programming 2 04-24-2005 09:33 PM
Splitting a network connection with packet forwarding phrawd Linux - Networking 1 06-30-2002 03:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration