|
| 1 | +#include <linux/types.h> |
| 2 | +#include <linux/bitops.h> |
| 3 | +#include <linux/cred.h> |
| 4 | +#include <linux/init.h> |
| 5 | +#include <linux/io.h> |
| 6 | +#include <linux/kernel.h> |
| 7 | +#include <linux/kmod.h> |
| 8 | +#include <linux/list.h> |
| 9 | +#include <linux/miscdevice.h> |
| 10 | +#include <linux/module.h> |
| 11 | +#include <linux/mutex.h> |
| 12 | +#include <linux/net.h> |
| 13 | +#include <linux/poll.h> |
| 14 | +#include <linux/skbuff.h> |
| 15 | +#include <linux/smp.h> |
| 16 | +#include <linux/socket.h> |
| 17 | +#include <linux/stddef.h> |
| 18 | +#include <linux/unistd.h> |
| 19 | +#include <linux/wait.h> |
| 20 | +#include <linux/workqueue.h> |
| 21 | +#include <net/sock.h> |
| 22 | +#include <net/inet_common.h> |
| 23 | + |
| 24 | +#include "pvcalls-front.h" |
| 25 | + |
| 26 | +static int |
| 27 | +pvcalls_bind(struct socket *sock, struct sockaddr *addr, int addr_len) |
| 28 | +{ |
| 29 | + int ret; |
| 30 | + ret = pvcalls_front_socket(sock); |
| 31 | + if (ret < 0) |
| 32 | + return ret; |
| 33 | + return pvcalls_front_bind(sock, addr, addr_len); |
| 34 | +} |
| 35 | + |
| 36 | +static int pvcalls_stream_connect(struct socket *sock, struct sockaddr *addr, |
| 37 | + int addr_len, int flags) |
| 38 | +{ |
| 39 | + int ret; |
| 40 | + ret = pvcalls_front_socket(sock); |
| 41 | + if (ret < 0) |
| 42 | + return ret; |
| 43 | + return pvcalls_front_connect(sock, addr, addr_len, flags); |
| 44 | +} |
| 45 | + |
| 46 | +static int pvcalls_accept(struct socket *sock, struct socket *newsock, int flags, bool kern) |
| 47 | +{ |
| 48 | + return pvcalls_front_accept(sock, newsock, flags); |
| 49 | +} |
| 50 | + |
| 51 | +static int pvcalls_getname(struct socket *sock, |
| 52 | + struct sockaddr *uaddr, int peer) |
| 53 | +{ |
| 54 | + DECLARE_SOCKADDR(struct sockaddr_in *, sin, uaddr); |
| 55 | + |
| 56 | + sin->sin_family = AF_INET; |
| 57 | + memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); |
| 58 | + return 0; |
| 59 | +} |
| 60 | + |
| 61 | +static unsigned int pvcalls_poll(struct file *file, struct socket *sock, |
| 62 | + poll_table *wait) |
| 63 | +{ |
| 64 | + return pvcalls_front_poll(file, sock, wait); |
| 65 | +} |
| 66 | + |
| 67 | +static int pvcalls_listen(struct socket *sock, int backlog) |
| 68 | +{ |
| 69 | + return pvcalls_front_listen(sock, backlog); |
| 70 | +} |
| 71 | + |
| 72 | +static int pvcalls_stream_sendmsg(struct socket *sock, struct msghdr *msg, |
| 73 | + size_t len) |
| 74 | +{ |
| 75 | + return pvcalls_front_sendmsg(sock, msg, len); |
| 76 | +} |
| 77 | + |
| 78 | +static int |
| 79 | +pvcalls_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, |
| 80 | + int flags) |
| 81 | +{ |
| 82 | + return pvcalls_front_recvmsg(sock, msg, len, flags); |
| 83 | +} |
| 84 | + |
| 85 | +static int pvcalls_release(struct socket *s) |
| 86 | +{ |
| 87 | + return pvcalls_front_release(s); |
| 88 | +} |
| 89 | + |
| 90 | +static int pvcalls_shutdown(struct socket *s, int h) |
| 91 | +{ |
| 92 | + return -ENOTSUPP; |
| 93 | +} |
| 94 | + |
| 95 | +static int sock_no_setsockopt(struct socket *sock, int level, int optname, |
| 96 | + sockptr_t optval, unsigned int optlen) |
| 97 | +{ |
| 98 | + return -ENOTSUPP; |
| 99 | +} |
| 100 | + |
| 101 | +static int sock_no_getsockopt(struct socket *sock, int level, int optname, |
| 102 | + char __user *optval, int __user *optlen) |
| 103 | +{ |
| 104 | + return -ENOTSUPP; |
| 105 | +} |
| 106 | + |
| 107 | +const struct proto_ops pvcalls_stream_ops = { |
| 108 | + .family = PF_INET, |
| 109 | + .owner = THIS_MODULE, |
| 110 | + .release = pvcalls_release, |
| 111 | + .bind = pvcalls_bind, |
| 112 | + .connect = pvcalls_stream_connect, |
| 113 | + .socketpair = sock_no_socketpair, |
| 114 | + .accept = pvcalls_accept, |
| 115 | + .getname = pvcalls_getname, |
| 116 | + .poll = pvcalls_poll, |
| 117 | + .ioctl = sock_no_ioctl, |
| 118 | + .listen = pvcalls_listen, |
| 119 | + .shutdown = pvcalls_shutdown, |
| 120 | + .setsockopt = sock_no_setsockopt, |
| 121 | + .getsockopt = sock_no_getsockopt, |
| 122 | + .sendmsg = pvcalls_stream_sendmsg, |
| 123 | + .recvmsg = pvcalls_stream_recvmsg, |
| 124 | + .mmap = sock_no_mmap, |
| 125 | + .sendpage = sock_no_sendpage, |
| 126 | +}; |
| 127 | + |
| 128 | +bool pvcalls = false; |
| 129 | +static __init int xen_parse_pvcalls(char *arg) |
| 130 | +{ |
| 131 | + pvcalls = true; |
| 132 | + return 0; |
| 133 | +} |
| 134 | +early_param("pvcalls", xen_parse_pvcalls); |
0 commit comments