Skip to content

Commit

Permalink
Merge pull request #2 from tsirakisn/patches-applied
Browse files Browse the repository at this point in the history
Apply viptables patches and add 4.19 kernel support
  • Loading branch information
jean-edouard authored Jun 19, 2019
2 parents 3ca4ab9 + d4a0ec9 commit 2bb6f34
Show file tree
Hide file tree
Showing 8 changed files with 552 additions and 7 deletions.
122 changes: 116 additions & 6 deletions argo-linux/argo-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,27 @@ H_argo_notify(xen_argo_ring_data_t *rd)
return HYPERVISOR_argo_op(XEN_ARGO_OP_notify, rd, NULL, 0, 0);
}

static int
H_viptables_add(xen_argo_viptables_rule_t* rule, int position)
{
return HYPERVISOR_argo_op(XEN_ARGO_OP_viptables_add, rule, NULL, 0,
position);
}

static int
H_viptables_del(xen_argo_viptables_rule_t* rule, int position)
{
return HYPERVISOR_argo_op(XEN_ARGO_OP_viptables_del, rule, NULL, 0,
position);
}

static int
H_viptables_list(xen_argo_viptables_list_t *rules_list)
{
return HYPERVISOR_argo_op(XEN_ARGO_OP_viptables_list, rules_list, NULL, 0,
0);
}

/*********************port/ring uniqueness **********/

/*Need to hold write lock for all of these*/
Expand Down Expand Up @@ -1539,6 +1560,28 @@ argo_notify(void)
DEBUG_APPLE;
}

/*********************** viptables ********************/
static int
viptables_add(struct argo_private *p, struct xen_argo_viptables_rule* rule,
int position)
{
return H_viptables_add(rule, position);
}

static int
viptables_del(struct argo_private *p, struct xen_argo_viptables_rule* rule,
int position)
{
return H_viptables_del(rule, position);
}

static int
viptables_list(struct argo_private *p,
struct xen_argo_viptables_list *rules_list)
{
return H_viptables_list(rules_list);
}

/*********************** state machines ********************/
static int
connector_state_machine(struct argo_private *p, struct argo_stream_header *sh)
Expand Down Expand Up @@ -3035,8 +3078,8 @@ static int
allocate_fd_with_private (void *private)
{
int fd;
const char * name = "";
struct file *f;
struct qstr name = { .name = "" };
struct path path;
struct inode *ind;

Expand All @@ -3048,34 +3091,42 @@ allocate_fd_with_private (void *private)
if ( fd < 0 )
return fd;

#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
path.dentry = d_alloc_pseudo(argo_mnt->mnt_sb, &name);
if ( unlikely(!path.dentry) )
{
if (unlikely(!path.dentry)) {
put_unused_fd(fd);
return -ENOMEM;
return -ENOMEM;
}
#endif

ind = new_inode(argo_mnt->mnt_sb);
ind->i_ino = get_next_ino();
ind->i_fop = argo_mnt->mnt_root->d_inode->i_fop;
ind->i_state = argo_mnt->mnt_root->d_inode->i_state;
ind->i_mode = argo_mnt->mnt_root->d_inode->i_mode;
ind->i_uid = current_fsuid();
ind->i_gid = current_fsgid();
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
d_instantiate(path.dentry, ind);

path.mnt = mntget(argo_mnt);
#endif

DEBUG_APPLE;
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
f = alloc_file(&path, FMODE_READ | FMODE_WRITE, &argo_fops_stream);
#else
f = alloc_file_pseudo(ind, argo_mnt, name, O_RDWR, &argo_fops_stream);
#endif
if ( !f )
{
//FIXME putback fd?
return -ENFILE;
}

f->private_data = private;
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
f->f_flags = O_RDWR;
#endif
fd_install (fd, f);

return fd;
Expand Down Expand Up @@ -3818,6 +3869,65 @@ argo_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
rc = argo_recvfrom (p, a.buf, a.len, a.flags, NULL, nonblock);
}
break;
case ARGOIOCVIPTABLESADD:
DEBUG_APPLE;
{
struct viptables_rule_pos rule_pos;
struct xen_argo_viptables_rule rule;

if ( copy_from_user(&rule_pos, (void __user *)arg,
sizeof(struct viptables_rule_pos)) ||
copy_from_user(&rule, rule_pos.rule,
sizeof(struct xen_argo_viptables_rule)) )
return -EFAULT;

rc = viptables_add(p, &rule, rule_pos.position);
}
break;
case ARGOIOCVIPTABLESDEL:
DEBUG_APPLE;
{
struct viptables_rule_pos rule_pos;
struct xen_argo_viptables_rule rule;

if ( copy_from_user(&rule_pos, (void __user *)arg,
sizeof(struct viptables_rule_pos)) )
return -EFAULT;

if ( rule_pos.rule )
{
if ( copy_from_user(&rule, rule_pos.rule,
sizeof(struct xen_argo_viptables_rule)) )
return -EFAULT;

rc = viptables_del(p, &rule, rule_pos.position);
}
else
rc = viptables_del(p, NULL, rule_pos.position);
}
break;
case ARGOIOCVIPTABLESLIST:
DEBUG_APPLE;
{
struct xen_argo_viptables_list rules_list;

if ( !access_ok(VERIFY_WRITE, (void __user *)arg,
sizeof (struct xen_argo_viptables_list)) )
return -EFAULT;

if ( get_user(rules_list.nrules,
&((struct xen_argo_viptables_list *)arg)->nrules) )
return -EFAULT;

rc = viptables_list(p, &rules_list);
if ( rc )
return rc;

if ( copy_to_user((void __user *)arg, &rules_list,
sizeof(struct xen_argo_viptables_list)) )
return -EFAULT;
}
break;
default:
printk(KERN_ERR "unknown ioctl: cmd=%x ARGOIOCACCEPT=%lx\n", cmd,
ARGOIOCACCEPT);
Expand Down
8 changes: 8 additions & 0 deletions argo-linux/include/linux/argo_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ struct argo_ring_id {
xen_argo_port_t aport;
};

struct viptables_rule_pos {
struct xen_argo_viptables_rule* rule;
int position;
};

#define ARGO_TYPE 'W'

#define ARGOIOCSETRINGSIZE _IOW (ARGO_TYPE, 1, uint32_t)
Expand All @@ -74,5 +79,8 @@ struct argo_ring_id {
#define ARGOIOCSEND32 _IOW (ARGO_TYPE, 9, struct argo_dev_32)
#define ARGOIOCRECV32 _IOW (ARGO_TYPE, 10, struct argo_dev_32)
#define ARGOIOCGETSOCKTYPE _IOW (ARGO_TYPE, 11, int)
#define ARGOIOCVIPTABLESADD _IOW (ARGO_TYPE, 12, struct viptables_rule_pos)
#define ARGOIOCVIPTABLESDEL _IOW (ARGO_TYPE, 13, struct viptables_rule_pos)
#define ARGOIOCVIPTABLESLIST _IOW (ARGO_TYPE, 14, uint32_t) /*unused args */

#endif
32 changes: 32 additions & 0 deletions argo-linux/include/xen/argo.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
/* Fixed-width type for "argo port" number. Nothing to do with evtchns. */
typedef uint32_t xen_argo_port_t;

#define XEN_ARGO_PORT_ANY 0xffffffffU

/* gfn type: 64-bit fixed-width on all architectures */
typedef uint64_t xen_argo_gfn_t;

Expand Down Expand Up @@ -166,6 +168,21 @@ struct xen_argo_ring_message_header
#endif
};

typedef struct xen_argo_viptables_rule
{
struct xen_argo_addr src;
struct xen_argo_addr dst;
uint32_t accept;
} xen_argo_viptables_rule_t;

#define XEN_ARGO_VIPTABLES_LIST_SIZE 8

typedef struct xen_argo_viptables_list
{
struct xen_argo_viptables_rule rules[XEN_ARGO_VIPTABLES_LIST_SIZE];
uint32_t nrules;
} xen_argo_viptables_list_t;

/*
* Hypercall operations
*/
Expand Down Expand Up @@ -275,4 +292,19 @@ struct xen_argo_ring_message_header
*/
#define XEN_ARGO_OP_notify 4

/*
* XEN_ARGO_OP_viptables_add
*/
#define XEN_ARGO_OP_viptables_add 6

/*
* XEN_ARGO_OP_viptables_del
*/
#define XEN_ARGO_OP_viptables_del 7

/*
* XEN_ARGO_OP_viptables_list
*/
#define XEN_ARGO_OP_viptables_list 8

#endif
5 changes: 4 additions & 1 deletion libargo/app/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
AM_CPPFLAGS = -I$(srcdir)/../src
AM_CFLAGS = -g

bin_PROGRAMS = ttcp-argo argo-proxy
bin_PROGRAMS = ttcp-argo argo-proxy viptables

ttcp_argo_SOURCES = ttcp.c
ttcp_argo_LDADD = ../src/libargo.la

argo_proxy_SOURCES = proxy.c
argo_proxy_LDADD = ../src/libargo.la

viptables_SOURCES = viptables.c
viptables_LDADD = ../src/libargo.la
Loading

0 comments on commit 2bb6f34

Please sign in to comment.