Unix Programming - Multiple PDUs in UDP Packet?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2005 > Multiple PDUs in UDP Packet?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Multiple PDUs in UDP Packet?
Michael B Allen

2005-05-20, 2:48 am

Is it ok to send multiple Protocol Data Units in one UDP packet?

For example, would it be normal (or wise) to encode 3 DNS requests into
a buffer and then send the entire buffer with one call to sendto(2)?

I'm writing some generic message multiplexing code and want to know if
I need to treat UDP (sendto) different from TCP (write).

Thanks,
Mike

Måns Rullgård

2005-05-20, 7:55 am

Michael B Allen <mba2000@ioplex.com> writes:

> Is it ok to send multiple Protocol Data Units in one UDP packet?
>
> For example, would it be normal (or wise) to encode 3 DNS requests into
> a buffer and then send the entire buffer with one call to sendto(2)?
>
> I'm writing some generic message multiplexing code and want to know if
> I need to treat UDP (sendto) different from TCP (write).


It all depends on what the receiving end is expecting. Are you
dealing with a standard protocol, or something of your own invention?

--
Måns Rullgård
mru@inprovide.com
Gordon Burditt

2005-05-20, 6:03 pm

>Is it ok to send multiple Protocol Data Units in one UDP packet?

What is a Protocol Data Unit? Is that the expensive, high-speed
version of the Bit Bucket?

>For example, would it be normal (or wise) to encode 3 DNS requests into
>a buffer and then send the entire buffer with one call to sendto(2)?


I know of nothing in the DNS spec that says a DNS server would know
what to do with such a packet. It might interpret it as one packet
with crap on the end. Or it might interpret it as an attack.

>I'm writing some generic message multiplexing code and want to know if
>I need to treat UDP (sendto) different from TCP (write).


There is no generic method of encoding multiple UDP packets into one.
The packet length in the UDP header is likely to be a critical part of
the packet. If you expect to send ONE packet with ONE IP header
containing multiple packets, expect trouble.

Gordon L. Burditt
Michael B Allen

2005-05-20, 6:03 pm

On Fri, 20 May 2005 13:08:18 +0200, Måns Rullgård wrote:

> Michael B Allen <mba2000@ioplex.com> writes:
>
>
> It all depends on what the receiving end is expecting. Are you
> dealing with a standard protocol, or something of your own invention?


I'm trying to be generic so it could be a standard protocol or it could
be custom. As it is I have buffers into which I encode messages. These
buffers are then "written" to sockets. The question is - if I encode
multiple messages into a single buffer can they all be sent with a single
call to write(2)/sendto(2)?

For TCP the answer is absolutely yes because any good protocol decoder
will have to deal with the scenario where some packets are coalesced due
to congestion, client/server speed differential, etc. Thus the decoder
must know how to determine the PDU boundry.

But with UDP this will not work (I don't think - this is what I'm asking)
because the packet *is* the PDU so a call to sendto(2) corresponds
directly to one recvfrom(2) at the other end (minus lost packets). Thus
if I try to sendto(2) a buffer containting 3 PDUs, the other end will
think it's one PDU and probably choke.

So, my message multiplexing code must behave differently depending on
wheather or not the socket is UDP or TCP. If it's TCP I can just write
whatevers in the buffer. For UDP I must either keep track of the PDU
boundies so I can ensure only one PDU is used with each call to sendto(2)
or ensure that the buffer is flushed with sendto(2) before encoding
another message.

Mike

David Schwartz

2005-05-20, 6:03 pm


"Michael B Allen" <mba2000@ioplex.com> wrote in message
news:pan.2005.05.20.20.52.29.190499@ioplex.com...

> But with UDP this will not work (I don't think - this is what I'm asking)
> because the packet *is* the PDU so a call to sendto(2) corresponds
> directly to one recvfrom(2) at the other end (minus lost packets). Thus
> if I try to sendto(2) a buffer containting 3 PDUs, the other end will
> think it's one PDU and probably choke.


> So, my message multiplexing code must behave differently depending on
> wheather or not the socket is UDP or TCP. If it's TCP I can just write
> whatevers in the buffer. For UDP I must either keep track of the PDU
> boundies so I can ensure only one PDU is used with each call to sendto(2)
> or ensure that the buffer is flushed with sendto(2) before encoding
> another message.


You have to give the other end what it is expecting. If it is expecting
that each UDP datagram will contain exactly one request, then that is what
you had better give it. If the protocol is defined to allow multiple
requests in a single datagram, and they fit, then you can send multiple
datagrams.

Normally, for UDP, each call to 'sendto' will result in a single
datagram being sent. This could, of course, result in multiple packets, but
they will be coalesced on the other end. Module drops and duplications, each
'sendto' will correspond to one 'recvfrom'.

DS


Måns Rullgård

2005-05-20, 6:03 pm

Michael B Allen <mba2000@ioplex.com> writes:

> On Fri, 20 May 2005 13:08:18 +0200, Måns Rullgård wrote:
>
>
> I'm trying to be generic so it could be a standard protocol or it could
> be custom. As it is I have buffers into which I encode messages. These
> buffers are then "written" to sockets. The question is - if I encode
> multiple messages into a single buffer can they all be sent with a single
> call to write(2)/sendto(2)?


What are you providing that write() doesn't?

--
Måns Rullgård
mru@inprovide.com
Barry Margolin

2005-05-21, 2:52 am

In article <118s2bd1kuj0r7c@corp.supernews.com>,
gordonb.lhj5q@burditt.org (Gordon Burditt) wrote:

>
> What is a Protocol Data Unit? Is that the expensive, high-speed
> version of the Bit Bucket?


Protocol Data Unit is standard terminology in the ISO OSI networking
architecture (the same documents that specified the well known 7 layers
of networking). A PDU is a particular layer's message.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Måns Rullgård

2005-05-21, 7:51 am

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <118s2bd1kuj0r7c@corp.supernews.com>,
> gordonb.lhj5q@burditt.org (Gordon Burditt) wrote:
>
>
> Protocol Data Unit is standard terminology in the ISO OSI networking
> architecture (the same documents that specified the well known 7 layers
> of networking).


And the same document that everybody is rightfully ignoring.

> A PDU is a particular layer's message.


If that's what it means, it doesn't really make sense talking about
putting several of them in one packet.

--
Måns Rullgård
mru@inprovide.com
Barry Margolin

2005-05-21, 5:49 pm

In article <yw1xhdgwamn9.fsf@ford.inprovide.com>,
Måns Rullgård <mru@inprovide.com> wrote:

> Barry Margolin <barmar@alum.mit.edu> writes:
>
>
> And the same document that everybody is rightfully ignoring.
>
>
> If that's what it means, it doesn't really make sense talking about
> putting several of them in one packet.


Sure it does. There are PDUs in each layer. So his question was
essentially whether you can put multiple Application PDUs (often called
"requests", "commands", and "responses") in a single Network PDU (a
datagram).

And as others have said, it depends totally on the Application layer
protocol. The OP mentioned DNS at some point -- it doesn't support
multiple requests or responses in a single datagram. Off the top of my
head I can't think of any UDP-based application protocols that do, but
there's nothing inherently preventing it. UDP-based protocols tend to
be fairly simple, which leads to the common arrangement of a one-to-one
mapping from command/response to datagram.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Michael B Allen

2005-05-21, 5:49 pm

On Sat, 21 May 2005 12:39:22 +0200, Måns Rullgård wrote:

>
> If that's what it means, it doesn't really make sense talking about
> putting several of them in one packet.


Why not? When you call sendto(2) you give it a buffer not a packet. Just
because it's one packet on the wire doesn't mean an application layer
protocol encoder couldn't put multiple PDUs into it.

The term "Protocol Data Unit" is nice because "request", "response",
"client", and "server" infer an orientation and some semantics about
protocol. For example, it is possible for a server to send a client
a request.

Mike

Barry Margolin

2005-05-21, 5:49 pm

In article <pan.2005.05.21.20.49.39.346149@ioplex.com>,
Michael B Allen <mba2000@ioplex.com> wrote:

> On Sat, 21 May 2005 12:39:22 +0200, Måns Rullgård wrote:
>
>
> Why not? When you call sendto(2) you give it a buffer not a packet. Just
> because it's one packet on the wire doesn't mean an application layer
> protocol encoder couldn't put multiple PDUs into it.
>
> The term "Protocol Data Unit" is nice because "request", "response",
> "client", and "server" infer an orientation and some semantics about
> protocol. For example, it is possible for a server to send a client
> a request.


My understanding is that the real purpose of the term PDU was to embody
the commonalities among layers. So the standard could make general
statements like "a layer-N PDU is encapsulated in a layer-(N-1) PDU."
Otherwise, many things would have to be restated for each layer, to use
their appropriate terminology: "A datagram is encapsulated in a series
of frames", "A command/request is encapsulated in a datagram", and so on.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Måns Rullgård

2005-05-21, 5:49 pm

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <yw1xhdgwamn9.fsf@ford.inprovide.com>,
> Måns Rullgård <mru@inprovide.com> wrote:
>
>
> Sure it does. There are PDUs in each layer. So his question was
> essentially whether you can put multiple Application PDUs (often called
> "requests", "commands", and "responses") in a single Network PDU (a
> datagram).


PDU, packet, whatever. The question is too generic to have an clear
answer. Besides, mixing terminology from ISO OSI and IP is not a good
idea.

--
Måns Rullgård
mru@inprovide.com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com