Skip to content

Commit 2bb6f34

Browse files
authored
Merge pull request #2 from tsirakisn/patches-applied
Apply viptables patches and add 4.19 kernel support
2 parents 3ca4ab9 + d4a0ec9 commit 2bb6f34

File tree

8 files changed

+552
-7
lines changed

8 files changed

+552
-7
lines changed

argo-linux/argo-module.c

Lines changed: 116 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,27 @@ H_argo_notify(xen_argo_ring_data_t *rd)
700700
return HYPERVISOR_argo_op(XEN_ARGO_OP_notify, rd, NULL, 0, 0);
701701
}
702702

703+
static int
704+
H_viptables_add(xen_argo_viptables_rule_t* rule, int position)
705+
{
706+
return HYPERVISOR_argo_op(XEN_ARGO_OP_viptables_add, rule, NULL, 0,
707+
position);
708+
}
709+
710+
static int
711+
H_viptables_del(xen_argo_viptables_rule_t* rule, int position)
712+
{
713+
return HYPERVISOR_argo_op(XEN_ARGO_OP_viptables_del, rule, NULL, 0,
714+
position);
715+
}
716+
717+
static int
718+
H_viptables_list(xen_argo_viptables_list_t *rules_list)
719+
{
720+
return HYPERVISOR_argo_op(XEN_ARGO_OP_viptables_list, rules_list, NULL, 0,
721+
0);
722+
}
723+
703724
/*********************port/ring uniqueness **********/
704725

705726
/*Need to hold write lock for all of these*/
@@ -1539,6 +1560,28 @@ argo_notify(void)
15391560
DEBUG_APPLE;
15401561
}
15411562

1563+
/*********************** viptables ********************/
1564+
static int
1565+
viptables_add(struct argo_private *p, struct xen_argo_viptables_rule* rule,
1566+
int position)
1567+
{
1568+
return H_viptables_add(rule, position);
1569+
}
1570+
1571+
static int
1572+
viptables_del(struct argo_private *p, struct xen_argo_viptables_rule* rule,
1573+
int position)
1574+
{
1575+
return H_viptables_del(rule, position);
1576+
}
1577+
1578+
static int
1579+
viptables_list(struct argo_private *p,
1580+
struct xen_argo_viptables_list *rules_list)
1581+
{
1582+
return H_viptables_list(rules_list);
1583+
}
1584+
15421585
/*********************** state machines ********************/
15431586
static int
15441587
connector_state_machine(struct argo_private *p, struct argo_stream_header *sh)
@@ -3035,8 +3078,8 @@ static int
30353078
allocate_fd_with_private (void *private)
30363079
{
30373080
int fd;
3081+
const char * name = "";
30383082
struct file *f;
3039-
struct qstr name = { .name = "" };
30403083
struct path path;
30413084
struct inode *ind;
30423085

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

3094+
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
30513095
path.dentry = d_alloc_pseudo(argo_mnt->mnt_sb, &name);
3052-
if ( unlikely(!path.dentry) )
3053-
{
3096+
if (unlikely(!path.dentry)) {
30543097
put_unused_fd(fd);
3055-
return -ENOMEM;
3098+
return -ENOMEM;
30563099
}
3100+
#endif
3101+
30573102
ind = new_inode(argo_mnt->mnt_sb);
30583103
ind->i_ino = get_next_ino();
30593104
ind->i_fop = argo_mnt->mnt_root->d_inode->i_fop;
30603105
ind->i_state = argo_mnt->mnt_root->d_inode->i_state;
30613106
ind->i_mode = argo_mnt->mnt_root->d_inode->i_mode;
30623107
ind->i_uid = current_fsuid();
30633108
ind->i_gid = current_fsgid();
3109+
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
30643110
d_instantiate(path.dentry, ind);
3065-
30663111
path.mnt = mntget(argo_mnt);
3112+
#endif
30673113

30683114
DEBUG_APPLE;
3115+
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
30693116
f = alloc_file(&path, FMODE_READ | FMODE_WRITE, &argo_fops_stream);
3117+
#else
3118+
f = alloc_file_pseudo(ind, argo_mnt, name, O_RDWR, &argo_fops_stream);
3119+
#endif
30703120
if ( !f )
30713121
{
30723122
//FIXME putback fd?
30733123
return -ENFILE;
30743124
}
30753125

30763126
f->private_data = private;
3127+
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) )
30773128
f->f_flags = O_RDWR;
3078-
3129+
#endif
30793130
fd_install (fd, f);
30803131

30813132
return fd;
@@ -3818,6 +3869,65 @@ argo_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
38183869
rc = argo_recvfrom (p, a.buf, a.len, a.flags, NULL, nonblock);
38193870
}
38203871
break;
3872+
case ARGOIOCVIPTABLESADD:
3873+
DEBUG_APPLE;
3874+
{
3875+
struct viptables_rule_pos rule_pos;
3876+
struct xen_argo_viptables_rule rule;
3877+
3878+
if ( copy_from_user(&rule_pos, (void __user *)arg,
3879+
sizeof(struct viptables_rule_pos)) ||
3880+
copy_from_user(&rule, rule_pos.rule,
3881+
sizeof(struct xen_argo_viptables_rule)) )
3882+
return -EFAULT;
3883+
3884+
rc = viptables_add(p, &rule, rule_pos.position);
3885+
}
3886+
break;
3887+
case ARGOIOCVIPTABLESDEL:
3888+
DEBUG_APPLE;
3889+
{
3890+
struct viptables_rule_pos rule_pos;
3891+
struct xen_argo_viptables_rule rule;
3892+
3893+
if ( copy_from_user(&rule_pos, (void __user *)arg,
3894+
sizeof(struct viptables_rule_pos)) )
3895+
return -EFAULT;
3896+
3897+
if ( rule_pos.rule )
3898+
{
3899+
if ( copy_from_user(&rule, rule_pos.rule,
3900+
sizeof(struct xen_argo_viptables_rule)) )
3901+
return -EFAULT;
3902+
3903+
rc = viptables_del(p, &rule, rule_pos.position);
3904+
}
3905+
else
3906+
rc = viptables_del(p, NULL, rule_pos.position);
3907+
}
3908+
break;
3909+
case ARGOIOCVIPTABLESLIST:
3910+
DEBUG_APPLE;
3911+
{
3912+
struct xen_argo_viptables_list rules_list;
3913+
3914+
if ( !access_ok(VERIFY_WRITE, (void __user *)arg,
3915+
sizeof (struct xen_argo_viptables_list)) )
3916+
return -EFAULT;
3917+
3918+
if ( get_user(rules_list.nrules,
3919+
&((struct xen_argo_viptables_list *)arg)->nrules) )
3920+
return -EFAULT;
3921+
3922+
rc = viptables_list(p, &rules_list);
3923+
if ( rc )
3924+
return rc;
3925+
3926+
if ( copy_to_user((void __user *)arg, &rules_list,
3927+
sizeof(struct xen_argo_viptables_list)) )
3928+
return -EFAULT;
3929+
}
3930+
break;
38213931
default:
38223932
printk(KERN_ERR "unknown ioctl: cmd=%x ARGOIOCACCEPT=%lx\n", cmd,
38233933
ARGOIOCACCEPT);

argo-linux/include/linux/argo_dev.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ struct argo_ring_id {
5858
xen_argo_port_t aport;
5959
};
6060

61+
struct viptables_rule_pos {
62+
struct xen_argo_viptables_rule* rule;
63+
int position;
64+
};
65+
6166
#define ARGO_TYPE 'W'
6267

6368
#define ARGOIOCSETRINGSIZE _IOW (ARGO_TYPE, 1, uint32_t)
@@ -74,5 +79,8 @@ struct argo_ring_id {
7479
#define ARGOIOCSEND32 _IOW (ARGO_TYPE, 9, struct argo_dev_32)
7580
#define ARGOIOCRECV32 _IOW (ARGO_TYPE, 10, struct argo_dev_32)
7681
#define ARGOIOCGETSOCKTYPE _IOW (ARGO_TYPE, 11, int)
82+
#define ARGOIOCVIPTABLESADD _IOW (ARGO_TYPE, 12, struct viptables_rule_pos)
83+
#define ARGOIOCVIPTABLESDEL _IOW (ARGO_TYPE, 13, struct viptables_rule_pos)
84+
#define ARGOIOCVIPTABLESLIST _IOW (ARGO_TYPE, 14, uint32_t) /*unused args */
7785

7886
#endif

argo-linux/include/xen/argo.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
/* Fixed-width type for "argo port" number. Nothing to do with evtchns. */
4444
typedef uint32_t xen_argo_port_t;
4545

46+
#define XEN_ARGO_PORT_ANY 0xffffffffU
47+
4648
/* gfn type: 64-bit fixed-width on all architectures */
4749
typedef uint64_t xen_argo_gfn_t;
4850

@@ -166,6 +168,21 @@ struct xen_argo_ring_message_header
166168
#endif
167169
};
168170

171+
typedef struct xen_argo_viptables_rule
172+
{
173+
struct xen_argo_addr src;
174+
struct xen_argo_addr dst;
175+
uint32_t accept;
176+
} xen_argo_viptables_rule_t;
177+
178+
#define XEN_ARGO_VIPTABLES_LIST_SIZE 8
179+
180+
typedef struct xen_argo_viptables_list
181+
{
182+
struct xen_argo_viptables_rule rules[XEN_ARGO_VIPTABLES_LIST_SIZE];
183+
uint32_t nrules;
184+
} xen_argo_viptables_list_t;
185+
169186
/*
170187
* Hypercall operations
171188
*/
@@ -275,4 +292,19 @@ struct xen_argo_ring_message_header
275292
*/
276293
#define XEN_ARGO_OP_notify 4
277294

295+
/*
296+
* XEN_ARGO_OP_viptables_add
297+
*/
298+
#define XEN_ARGO_OP_viptables_add 6
299+
300+
/*
301+
* XEN_ARGO_OP_viptables_del
302+
*/
303+
#define XEN_ARGO_OP_viptables_del 7
304+
305+
/*
306+
* XEN_ARGO_OP_viptables_list
307+
*/
308+
#define XEN_ARGO_OP_viptables_list 8
309+
278310
#endif

libargo/app/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
AM_CPPFLAGS = -I$(srcdir)/../src
2121
AM_CFLAGS = -g
2222

23-
bin_PROGRAMS = ttcp-argo argo-proxy
23+
bin_PROGRAMS = ttcp-argo argo-proxy viptables
2424

2525
ttcp_argo_SOURCES = ttcp.c
2626
ttcp_argo_LDADD = ../src/libargo.la
2727

2828
argo_proxy_SOURCES = proxy.c
2929
argo_proxy_LDADD = ../src/libargo.la
30+
31+
viptables_SOURCES = viptables.c
32+
viptables_LDADD = ../src/libargo.la

0 commit comments

Comments
 (0)