~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/um/drivers/vde_user.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
  4  */
  5 
  6 #include <stddef.h>
  7 #include <errno.h>
  8 #include <libvdeplug.h>
  9 #include <net_user.h>
 10 #include <um_malloc.h>
 11 #include "vde.h"
 12 
 13 static int vde_user_init(void *data, void *dev)
 14 {
 15         struct vde_data *pri = data;
 16         VDECONN *conn = NULL;
 17         int err = -EINVAL;
 18 
 19         pri->dev = dev;
 20 
 21         conn = vde_open(pri->vde_switch, pri->descr, pri->args);
 22 
 23         if (conn == NULL) {
 24                 err = -errno;
 25                 printk(UM_KERN_ERR "vde_user_init: vde_open failed, "
 26                        "errno = %d\n", errno);
 27                 return err;
 28         }
 29 
 30         printk(UM_KERN_INFO "vde backend - connection opened\n");
 31 
 32         pri->conn = conn;
 33 
 34         return 0;
 35 }
 36 
 37 static int vde_user_open(void *data)
 38 {
 39         struct vde_data *pri = data;
 40 
 41         if (pri->conn != NULL)
 42                 return vde_datafd(pri->conn);
 43 
 44         printk(UM_KERN_WARNING "vde_open - we have no VDECONN to open");
 45         return -EINVAL;
 46 }
 47 
 48 static void vde_remove(void *data)
 49 {
 50         struct vde_data *pri = data;
 51 
 52         if (pri->conn != NULL) {
 53                 printk(UM_KERN_INFO "vde backend - closing connection\n");
 54                 vde_close(pri->conn);
 55                 pri->conn = NULL;
 56                 kfree(pri->args);
 57                 pri->args = NULL;
 58                 return;
 59         }
 60 
 61         printk(UM_KERN_WARNING "vde_remove - we have no VDECONN to remove");
 62 }
 63 
 64 const struct net_user_info vde_user_info = {
 65         .init           = vde_user_init,
 66         .open           = vde_user_open,
 67         .close          = NULL,
 68         .remove         = vde_remove,
 69         .add_address    = NULL,
 70         .delete_address = NULL,
 71         .mtu            = ETH_MAX_PACKET,
 72         .max_packet     = ETH_MAX_PACKET + ETH_HEADER_OTHER,
 73 };
 74 
 75 void vde_init_libstuff(struct vde_data *vpri, struct vde_init *init)
 76 {
 77         struct vde_open_args *args;
 78 
 79         vpri->args = uml_kmalloc(sizeof(struct vde_open_args), UM_GFP_KERNEL);
 80         if (vpri->args == NULL) {
 81                 printk(UM_KERN_ERR "vde_init_libstuff - vde_open_args "
 82                        "allocation failed");
 83                 return;
 84         }
 85 
 86         args = vpri->args;
 87 
 88         args->port = init->port;
 89         args->group = init->group;
 90         args->mode = init->mode ? init->mode : 0700;
 91 
 92         args->port ?  printk("port %d", args->port) :
 93                 printk("undefined port");
 94 }
 95 
 96 int vde_user_read(void *conn, void *buf, int len)
 97 {
 98         VDECONN *vconn = conn;
 99         int rv;
100 
101         if (vconn == NULL)
102                 return 0;
103 
104         rv = vde_recv(vconn, buf, len, 0);
105         if (rv < 0) {
106                 if (errno == EAGAIN)
107                         return 0;
108                 return -errno;
109         }
110         else if (rv == 0)
111                 return -ENOTCONN;
112 
113         return rv;
114 }
115 
116 int vde_user_write(void *conn, void *buf, int len)
117 {
118         VDECONN *vconn = conn;
119 
120         if (vconn == NULL)
121                 return 0;
122 
123         return vde_send(vconn, buf, len, 0);
124 }
125 
126 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php