22 #include <linux/virgo.h>
108 int clone_func(
void* args)
114 FPTR get_function_ptr_from_str(
char* cloneFunction)
120 virgocloudexec_init(
void)
122 printk(KERN_INFO
"doing init() of virgocloudexec kernel module\n");
125 EXPORT_SYMBOL(virgocloudexec_init);
127 static int virgocloudexec_create(
void)
129 memset(&sin, 0,
sizeof(
struct sockaddr_in));
130 sin.sin_family=PF_INET;
131 sin.sin_addr.s_addr=htonl(INADDR_ANY);
132 sin.sin_port=htons(10000);
135 iov.iov_base=(
void*)buffer;
136 iov.iov_len=BUF_SIZE;
137 error = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
138 printk(KERN_INFO
"sock_create() returns error code: %d\n",error);
140 error = kernel_bind(sock, (
struct sockaddr*)&sin,
sizeof(
struct sockaddr_in));
141 printk(KERN_INFO
"kernel_bind() returns error code: %d\n",error);
143 error = kernel_listen(sock, 2);
144 printk(KERN_INFO
"kernel_listen() returns error code: %d\n", error);
147 error = kernel_accept(sock, &clientsock, 0);
149 printk(KERN_INFO
"kernel_accept() returns -EAGAIN\n");
150 printk(KERN_INFO
"kernel_accept() returns error code: %d\n",error);
153 EXPORT_SYMBOL(virgocloudexec_create);
155 static int virgocloudexec_recvfrom(
void)
160 len = kernel_recvmsg(clientsock, &msg, &iov, buflen, nr, msg.msg_flags);
161 printk(KERN_INFO
"kernel_recvmsg() returns len: %d\n",len);
166 cloneFunction = kstrdup(iov.iov_base,GFP_KERNEL);
167 cloneFunction_ptr = get_function_ptr_from_str(cloneFunction);
168 task=kthread_create(cloneFunction_ptr, (
void*)args,
"cloudclonethread");
169 strcpy(buffer,
"cloudclonethread executed");
172 EXPORT_SYMBOL(virgocloudexec_recvfrom);
174 static int virgocloudexec_sendto(
void)
176 iov.iov_base=(
void*)buffer;
178 kernel_sendmsg(clientsock, &msg, &iov, nr, buflen);
241 EXPORT_SYMBOL(virgocloudexec_sendto);
245 virgocloudexec_exit(
void)
247 printk(KERN_INFO
"exiting virgocloudexec kernel module \n");
250 EXPORT_SYMBOL(virgocloudexec_exit);
253 MODULE_LICENSE(
"GPL");
254 module_init(virgocloudexec_init);
255 module_exit(virgocloudexec_exit);