[comp.unix.wizards] Datagrams Outside the Kernel

mack@inco.UUCP (Dave Mack) (06/27/90)

I have question which may (or may not) be worthy of this august
assemblage.

I have a program running in user context which has a datagram (IP,
for example) in a buffer. I need to hand this datagram over to
the kernel in such a way that it gets transmitted to whatever
Internet address lurks in the IP header.

I also need to solve the inverse problem: getting a datagram in
its raw form from the kernel when it arrives at my machine.

What makes this tough is that I have to do this without modifying
the kernel source. I can add pseudo-device drivers, if necessary,
but I can't change anything whose source doesn't come with a
binary Unix distribution.

The current context of this is a Sun-2/120 under SunOS3.4, but
I'd like to be able to run on any system with BSD networking.
Note: I can't assume the availability of streams.

So. Is this possible or am I screwed? Does any PD software to
do something like this exist?

Thanks very much,
Dave Mack
mack@inco.mdc.com
{uunet!alembic,pyrdc,sundc}!inco!mack
-- 
Dave Mack				McDonnell Douglas Electronic Systems
uunet!inco!mack, inco%mack@uunet.uu.net			(703)883-3911
All opinions expressed are my own and do not reflect those of MDESC. Ever.

jc@minya.UUCP (John Chambers) (07/02/90)

In article <8009@inco.UUCP>, mack@inco.UUCP (Dave Mack) writes:
> 
> I have question which may (or may not) be worthy of this august
> assemblage.
> 
> I have a program running in user context which has a datagram (IP,
> for example) in a buffer. I need to hand this datagram over to
> the kernel in such a way that it gets transmitted to whatever
> Internet address lurks in the IP header.
> 
> I also need to solve the inverse problem: getting a datagram in
> its raw form from the kernel when it arrives at my machine.

I'll second this request.  I've been asked whether I can build an
application which, in effect, "volunteers" to handle any IP address
that the kernel doesn't know what to do with.  In perusing TFM, I
haven't found any hint that this is possible.  Does any extant IP
implementation supply a hook that allows this?

Actually, I can demonstrate a kludge that solves the problem.  What
I do is take my SLIP package and route all the traffic to it, and
at the other end of the serial link is my application.  But shoving
all the traffic through a 19.2Kb bottleneck isn't exactly my idea
of an ideal solution to the problem.

And I suppose I could carry this one step further:  Route all the
traffic back onto the ethernet to another machine which doesn't
have IP at all, but has only my application sitting there gobbling
up all incoming traffic.  I.e., give up totally on Unix and write
my own low-level system from scratch.  Sounds like fun, but I'm
not fond of swatting flies with a sledgehammer.

(To play devil's advocate, it has been suggested that I could do it
easily on DOS.  After all, it is easy for a DOS application to take
over an interrupt.  I've done it before...  ;-)

Any better ideas?  Is Unix up to the task?

-- 
Uucp: ...!{harvard.edu,ima.com,eddie.mit.edu,ora.com}!minya!jc (John Chambers)
Home: 1-617-484-6393
Work: 1-508-952-3274
Cute-Saying: [I've gotta get a new one of these some day.]

matt@group-w.uchicago.edu (Matt Crawford) (07/03/90)

In article <414@minya.UUCP>, jc@minya (John Chambers) writes:
) I'll second this request.  I've been asked whether I can build an
) application which, in effect, "volunteers" to handle any IP address
) that the kernel doesn't know what to do with.  In perusing TFM, I
) haven't found any hint that this is possible.  
) Any better ideas?  Is Unix up to the task?

I think I know how this could be done.  I once wrote a sort of a
"chimeral" device driver which provided open()/read()/write() access and
was also a network interface.  In that case it was meant to be used just
one way or the other at any given time, but in your case I would make
the if_output() routine hand packets to the read queue of the character
device.

Then you'd configure a default route to point to this interface.  Voila!
Packets addressed to "any IP address that the kernel doesn't know what
to do with" go to the process reading the character device.

You did say "build an application," while the above needs a new device
driver, but since you don't need source to your kernel, this probably
counts as a solution.
				Matt Crawford

akhale@chamomile.uucp (Abhijit Khale) (07/03/90)

In article <414@minya.UUCP> jc@minya.UUCP (John Chambers) writes:
>In article <8009@inco.UUCP>, mack@inco.UUCP (Dave Mack) writes:
>> 
>> I have question which may (or may not) be worthy of this august
>> assemblage.
>> 
>> I have a program running in user context which has a datagram (IP,
>> for example) in a buffer. I need to hand this datagram over to
>> the kernel in such a way that it gets transmitted to whatever
>> Internet address lurks in the IP header.
>> 
>> I also need to solve the inverse problem: getting a datagram in
>> its raw form from the kernel when it arrives at my machine.

I missed the original article, but .. 

Use raw IP sockets. These allow you to get a datagram in its raw
form when it arrives at the machine [ Actually when
all fragments of that datagram arrive. ]. You will also get the header.

Raw IP sockets can also be used to send out IP packets with a 
particular header. Not all fields in the IP header can be manipulated,
though. You cannot set the src addr to an addr not that of the
machine. Also, the TTL and the checksum ( obviously ) are filled in 
by the system. 

>
>I'll second this request.  I've been asked whether I can build an
>application which, in effect, "volunteers" to handle any IP address
>that the kernel doesn't know what to do with.  In perusing TFM, I
>haven't found any hint that this is possible.  Does any extant IP
>implementation supply a hook that allows this?

A  raw socket would enable you to do that. [ I think so anyway,
since I am not sure I understand your question fully ]. 

man 4 ip will tell you more about how to open a raw socket. 

Abhijit 
akhale@parc.xerox.com