netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, kelly@au1.ibm.com, rusty@rustcorp.com.au
Subject: Re: [1/1] netchannel subsystem.
Date: Tue, 16 May 2006 11:07:17 +0400	[thread overview]
Message-ID: <20060516070717.GA12719@2ka.mipt.ru> (raw)
In-Reply-To: <20060516065923.GA8649@2ka.mipt.ru>

On Tue, May 16, 2006 at 10:59:23AM +0400, Evgeniy Polyakov (johnpol@2ka.mipt.ru) wrote:
> On Mon, May 15, 2006 at 11:57:12PM -0700, David S. Miller (davem@davemloft.net) wrote:
> > From: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
> > Date: Tue, 16 May 2006 10:19:09 +0400
> > 
> > > +static int netchannel_convert_skb_ipv4(struct sk_buff *skb, struct unetchannel *unc)
> > > +{
> >  ...
> > > +	switch (unc->proto) {
> > > +		case IPPROTO_TCP:
> >  ...
> > > +		case IPPROTO_UDP:
> >  ...
> > 
> > Why do people write code like this?
> > 
> > Port location is protocol agnostic, there are always 2
> > 16-bit ports at beginning of header without exception.
> > 
> > Without this, ICMP would be useless :-)
> 
> And what if we use ESP which would place it's hashed sequence number as
> port?

Actually it should be one big hash, no matter if it is ipv4/tcp or
ipv6/esp, src/dst/sport/dport/proto were created just to allow easier
debug in ipv4 environment.

Attached patch for userspace copy:

--- /tmp/netchannel.1	2006-05-16 10:33:17.000000000 +0400
+++ /tmp/netchannel.2	2006-05-16 11:23:44.000000000 +0400
@@ -35,10 +35,10 @@
  
 diff --git a/include/linux/netchannel.h b/include/linux/netchannel.h
@@ -100,6 +100,7 @@
 +
 +	struct page *		(*nc_alloc_page)(unsigned int size);
 +	void			(*nc_free_page)(struct page *page);
++	int			(*nc_read_data)(struct netchannel *, unsigned int *len, void __user *arg);
 +
 +	struct sk_buff_head 	list;
 +};
@@ -228,10 +229,10 @@
  		ret = deliver_skb(skb, pt_prev, orig_dev);
 diff --git a/net/core/netchannel.c b/net/core/netchannel.c
 --- /dev/null
 +++ b/net/core/netchannel.c
-@@ -0,0 +1,583 @@
+@@ -0,0 +1,649 @@
 +/*
 + * 	netchannel.c
 + * 
@@ -578,6 +579,40 @@
 +	return err;
 +}
 +
++/*
++ * Actually it should be something like recvmsg().
++ */
++static int netchannel_copy_to_user(struct netchannel *nc, unsigned int *len, void __user *arg)
++{
++	unsigned int copied;
++	struct sk_buff *skb;
++	struct iovec to;
++	int err = -EINVAL;
++	
++	to.iov_base = arg;
++	to.iov_len = *len;
++
++	skb = skb_dequeue(&nc->list);
++	if (!skb)
++		return -EAGAIN;
++
++	copied = skb->len;
++	if (copied > *len)
++		copied = *len;
++	
++	if (skb->ip_summed==CHECKSUM_UNNECESSARY) {
++		err = skb_copy_datagram_iovec(skb, 0, &to, copied);
++	} else {
++		err = skb_copy_and_csum_datagram_iovec(skb,0, &to);
++	}
++
++	*len = (err == 0)?copied:0;
++
++	kfree_skb(skb);
++
++	return err;
++}
++
 +static int netchannel_create(struct unetchannel *unc)
 +{
 +	struct netchannel *nc;
@@ -612,6 +647,8 @@
 +	atomic_set(&nc->refcnt, 1);
 +	memcpy(&nc->unc, unc, sizeof(struct unetchannel));
 +
++	nc->nc_read_data = &netchannel_copy_to_user;
++
 +	hlist_add_head_rcu(&nc->node, &bucket->head);
 +
 +out_unlock:
@@ -658,6 +695,30 @@
 +	return 0;
 +}
 +
++static int netchannel_recv_data(struct unetchannel_control *ctl, void __user *data)
++{
++	int ret = -ENODEV;
++	struct netchannel_cache_head *bucket;
++	struct netchannel *nc;
++	
++	bucket = netchannel_bucket(&ctl->unc);
++
++	mutex_lock(&bucket->mutex);
++
++	nc = netchannel_check_full(&ctl->unc, bucket);
++	if (!nc)
++		nc = netchannel_check_dest(&ctl->unc, bucket);
++
++	if (!nc)
++		goto out_unlock;
++
++	ret = nc->nc_read_data(nc, &ctl->len, data);
++
++out_unlock:
++	mutex_unlock(&bucket->mutex);
++	return ret;
++}
++
 +asmlinkage int sys_netchannel_control(void __user *arg)
 +{
 +	struct unetchannel_control ctl;
@@ -677,10 +738,16 @@
 +		case NETCHANNEL_REMOVE:
 +			ret = netchannel_remove(&ctl.unc);
 +			break;
++		case NETCHANNEL_READ:
++			ret = netchannel_recv_data(&ctl, arg + sizeof(struct unetchannel_control));
++			break;
 +		default:
 +			ret = -EINVAL;
 +			break;
 +	}
++	
++	if (copy_to_user(arg, &ctl, sizeof(struct unetchannel_control)))
++		return -ERESTARTSYS;
 +
 +	return ret;
 +}


-- 
	Evgeniy Polyakov

  parent reply	other threads:[~2006-05-16  7:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-26 11:47 [PATCH 1/3] Rough VJ Channel Implementation - vj_core.patch Kelly Daly
2006-04-26  7:33 ` David S. Miller
2006-04-27  3:31   ` Kelly Daly
2006-04-27  6:25     ` David S. Miller
2006-04-27 11:51       ` Evgeniy Polyakov
2006-04-27 20:09         ` David S. Miller
2006-04-28  6:05           ` Evgeniy Polyakov
2006-05-04  2:59       ` Kelly Daly
2006-05-04 23:22         ` David S. Miller
2006-05-05  1:31           ` Rusty Russell
2006-04-26  7:59 ` David S. Miller
2006-05-04  7:28   ` Kelly Daly
2006-05-04 23:11     ` David S. Miller
2006-05-05  2:48       ` Kelly Daly
2006-05-16  1:02         ` Kelly Daly
2006-05-16  1:05           ` David S. Miller
2006-05-16  1:15             ` Kelly Daly
2006-05-16  5:16           ` David S. Miller
2006-06-22  2:05             ` Kelly Daly
2006-06-22  3:58               ` James Morris
2006-06-22  4:31                 ` Arnaldo Carvalho de Melo
2006-06-22  4:36                 ` YOSHIFUJI Hideaki / 吉藤英明
2006-07-08  0:05               ` David Miller
2006-05-16  6:19           ` [1/1] netchannel subsystem Evgeniy Polyakov
2006-05-16  6:57             ` David S. Miller
2006-05-16  6:59               ` Evgeniy Polyakov
2006-05-16  7:06                 ` David S. Miller
2006-05-16  7:15                   ` Evgeniy Polyakov
2006-05-16  7:07                 ` Evgeniy Polyakov [this message]
2006-05-16 17:34               ` [1/1] Netchannel subsyste Evgeniy Polyakov
2006-05-18 10:34                 ` Netchannel subsystem update Evgeniy Polyakov
2006-05-20 15:52                   ` Evgeniy Polyakov
2006-05-22  6:06                     ` David S. Miller
2006-05-22 16:34                       ` [Netchannel] Full TCP receiving support Evgeniy Polyakov
2006-05-24  9:38                         ` Evgeniy Polyakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060516070717.GA12719@2ka.mipt.ru \
    --to=johnpol@2ka.mipt.ru \
    --cc=davem@davemloft.net \
    --cc=kelly@au1.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).