c - Autonomically sending a message from kernel-module to user-space application without relying on the invoke of input. from user-space -


i give detailed exp of program , lead issue regarding use of netlink socket communication.
the last paragraph asks actual question need answer for, might wanna start peeking first.

disclaimer before start:
- have made earlier search before asking here , did not find complete solution / alternative issue.
- know how initialize module , insert kernel.
- know handle communication between module , user-space without using netlink sockets. meaning using struct file_operations func pointers assignments later invoked module program whenever user attempts read/write etc. , answer user using copy_to_user / copy_from_user.
- topic refers linux os, mint 17 dist.
- language c

okay, building system 3 components:
1. user.c : user application (user types commands here)
2. storage.c : storage device ('virtual' disk-on-key)
3. device.ko : kernel module (used proxy between 1. , 2.)

the purpose of system able (as user) to:
- copy files to virtual disk-on-key device (2) - "upload" local directory belongs user.
- save files from virtual device on local directory - "download" device storage user directory.

design:
assuming programs (1),(2) compiled , running + (3) has inserted using bash command ' sudo insmod device.ko ' , following should work (simulation ofc):

step 1 (in user.c) -> user types 'download file.txt'
step 2 (in device.ko) -> device recognizes user have tried 'write' (actually user passing string "download file.txt") , invokes 'write' implementation of method set on struct file_operation earlier on module_init().
device (kernel module) passes data (string command) storage.c application, expecting answer later retrieved user.c application.
step 3 (in storage.c) -> now, lets program performs busy-wait loop of 'readmsg()' , that's how request module event triggered , recognized, storage device recognizes module has sent request (string command \ data). now, storage programs shall perform implementation of function 'x' send data requested using sendmsg() somewhere inside function.

now, here comes issue. usually, on of examples i've looked on web, communication between kernel-module , user-space (or storage.c program in our case) using netlink triggered user-space , not vice versa. meaning sendmsg() function user-space invokes 'request(struct sk_buff *skb)' method (which set on module_init() part following:

struct netlink_kernel_cfg cfg = {     .input = request            // when storage.c sends something, invokes request function }; 

so when storage.c performs like:

sendmsg(sock_fd,&msg,0);                        // send msg module 

the module invokes , runs the:

static void request(struct sk_buff *skb) {     char *msg ="hello kernel";     msg_size=strlen(msg);      netlink_holder=(struct nlmsghdr*)skb->data;     printk(kern_info "netlink received msg payload:%s\n",(char*)nlmsg_data(netlink_holder));      pid = netlink_holder->nlmsg_pid;                                // pid of sending process       skb_out = nlmsg_new(msg_size,0);      if(!skb_out){         printk(kern_err "failed allocate new skb\n");         return;     }       netlink_holder=nlmsg_put(skb_out,0,0,nlmsg_done,msg_size,0);    // add new netlink message skb. more info: http://elixir.free-electrons.com/linux/v3.2/source/include/net/netlink.h#l491     netlink_cb(skb_out).dst_group = 0;                              // not in multicast group     strncpy(nlmsg_data(netlink_holder),msg,msg_size);               // assign data char* (variable msg)      result=nlmsg_unicast(sock_netlink,skb_out,pid);                 // send data storage. more info: http://elixir.free-electrons.com/linux/latest/source/include/net/netlink.h#l598      if(result<0)         printk(kern_info "error while sending bak user\n"); } 

and big chunk, thing im interesting in doing this:

result=nlmsg_unicast(sock_netlink,skb_out,pid);                 // send data storage. 

but can't use nlmsg_unicast() without having strcut sk_buff* provided automatically me whenever there's invoke storage.c !

to sum everything:
how send msg device.ko (kernel module) user-space withtout having wait request invoke / rely on provided strcut sk_buff parameter earlier shown 'request()' method ?

hope sums point. thanks.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -