kar
kar

Reputation: 2795

Develop simple net_device in the linux kernel

I am trying to implement a netdevice (net_device) in linux kernel. This is simple net_device which pass the command/data from user space to kernel space and vice versa this is the goal of this simple net_device. I am using socket for passing command/data from user space to kernel space . After googling i successed in registering net_device and able to see my device in /sys/class/net/abc0 (device name) when coming to file operation there is no clear idea of the flow

 struct net_device_ops
 {   
   .ndo_open  =open,

   .ndo_close = close,

   .ndo_start_xmit = start_xmit   
 }

There is no clear flow/information about simple net_device (except ethernet) can any suggest a link/pdf.

I tried writing simple socket program to test open,close,start_xmit. where socket read/write is not calling open,close,star_xmit . Is there any way to test the developed net_device ?

Thank you

Upvotes: 2

Views: 2171

Answers (2)

John
John

Reputation: 449

SIOCSIFFLAGS, -> IFF_UP you can actually set or unset it while doing an ioctl to the netdevice abc0.

first off you have to create a dgram socket,

then use ifreq structure defined in net/if.h

and fill interface and iff_flags

iff_flags can be set with IFF_UP or can be negated with the same IFF_UP to make interface down

and then close the socket.

#include <net/if.h>

....

sock = socket(AF_INET, SOCK_DGRAM, 0);

if (sock < 0) {

   goto fail;

}

struct ifreq ifreq;

strcpy(ifreq.ifr_name, "abcd0");

ifreq.iff_flags |= IFF_UP;

if (ioctl(sock, &ifreq, sizeof(ifreq) < 0) {

    perror("ioctl setting interface up");

}

ifreq.iff_flags ~= IFF_UP;

if (ioctl(sock, &ifreq, sizeof(ifreq) < 0) {

    perror("ioctl setting interface down");

}

close(sock);

offtopic:

will you please share your code? we can understand too about your network device :)

Upvotes: 1

kar
kar

Reputation: 2795

I found how to test the open,close function .

  • type : ifconfig abc0(Device name) up will call open method

  • type : ifconfig abc0(Device name) down will call close method

Can some one help me how to test these methods with sockets.

Upvotes: 1

Related Questions