Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jun 1999 11:25:42 -0400 (EDT)
From:      Dan Seguin <dseg@texar.com>
To:        "Brian F. Feldman" <green@unixhelp.org>
Cc:        FreeBSD Hackers <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: Connect and so on..
Message-ID:  <Pine.BSF.4.05.9906251107580.28392-100000@pak2.texar.com>
In-Reply-To: <Pine.BSF.4.10.9906231833270.89612-100000@janus.syracuse.net>

next in thread | previous in thread | raw e-mail | index | archive | help


On Wed, 23 Jun 1999, Brian F. Feldman wrote:

> On Wed, 23 Jun 1999, Dan Seguin wrote:
> 
> > 

[snip]
> > I use the calling proc's table as it is passed to the system call, and am
> > trying to call socket and connect as if the user process originally called
> > them one by one (from userland syscall 97 and 98). I seem to be getting
> > the correct behaviour from socket, but the connect call fails. After
> > DDB'ing and breaking on the call to connect, it appears to fail at copyin
> > with an EFAULT (invalid address). Call stack: copyin from getsockaddr from
> > connect. What am I missing here, and/or what incorrect assumptions have I
> > made? I'm including the actual system call function below.

> copyin() is done to get the sockaddr from the connect call. A copyin() is a user-space
> to kernel-space memory copy, so you have a problem in your code (I'll point out where
> below).


> > -------- CODE starts ----------------
> > 
> > static int init_comms(p, uap)
> > struct proc *p;
> > register struct nosys_args *uap;
> > {
> >   int sockfd1, stat; 
> >   struct socket_args socket_uap;
> >   struct connect_args connect_uap;
> >   static struct sockaddr_in servaddr;
> 
> This needs to be a valid structure in USER space, not kernel.

OK. I suspected as much. Question is: how do I open a connection from
KERNEL space? 

> 
> >  
> >   socket_uap.domain = PF_LOCAL;
> >   socket_uap.type = SOCK_STREAM;
> >   socket_uap.protocol = 0; 
> > 
> >   stat = socket(p, &socket_uap);
> if (stat)
> 	return stat;

> >   servaddr.sin_family = AF_LOCAL;
> >   servaddr.sin_port   = htons(13);
> >   servaddr.sin_len    = sizeof servaddr;

> >  if ( inet_aton((char *) "127.0.0.1", &servaddr.sin_addr) <= 0 )
> This is a bogus cast. const char * to char *?
> >     printf("\ninet_aton failed.\n");
> So return EINVAL.

Yes. Forgot to take that out before submitting. I was humouring a
colleague by trying this out.

[snip]

> >   connect_uap.s = sockfd1;
> >   connect_uap.name = (caddr_t) &servaddr;
> 
> That's the problem. It needs to point to (say) uap->servaddr;

See above. I need to do this inside kernel. The client (or calling)
process has no knowledge of the connection.

> 
> >   connect_uap.namelen = sizeof servaddr;
> >   
> >   stat = 0;
> >   stat = connect(p, &connect_uap);
> >   
> >   printf("\nConnect Stat: %d\n", stat);

[snip]

>  Brian Fundakowski Feldman      _ __ ___ ____  ___ ___ ___  
>  green@FreeBSD.org                   _ __ ___ | _ ) __|   \ 
>      FreeBSD: The Power to Serve!        _ __ | _ \._ \ |) |
>        http://www.FreeBSD.org/              _ |___/___/___/ 


As I said earlier in this post, I need to open a connection to the outside
(presumably) from the KERNEL. The reason for this is that the calling
process has no knowledge of the connection, and the connection,
communication, response from other end, and closing of connection must be
one atomic, discreet event that will not get interrupted. I assumed that
this would have to be done from the KERNEL but maybe I'm wrong here. If I
could use an external (userland) daemon with shared space, the KERNEL
could write to it and the daemon would do the rest, but how do I keep ALL
other processes (except system processes) from running? The latter didn't
seem feasible to me.

Thanks!


Dan Seguin





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9906251107580.28392-100000>