Question about npkt's and net_bufs

What is the correct way to modify data contained within buffers on the
way down the protocol stack?

For example, say i am a filter driver that sits below the ip layer, and
i want to modify TCP/IP packets on the way down. Assume that there is
only one buffer with mutltiple iov’s attached to the packet. I want to
copy all the iov’s into one larger iov, and send the packet along. Would
it be ok to allocate a new buffer, copy the data from the old iovs into
the new one, remove the old buffer from the list of buffers, and then
add the new one? Or do i need to create a new npkt_t with a new buffer
list, register with tx_done, send the new packet, and call tx_done on
the original packet when my tx_done gets called?

Thanks for any insight.

Steven Erickson <sojg@mediaone.net> wrote:

What is the correct way to modify data contained within buffers on the
way down the protocol stack?

For example, say i am a filter driver that sits below the ip layer, and
i want to modify TCP/IP packets on the way down. Assume that there is
only one buffer with mutltiple iov’s attached to the packet. I want to
copy all the iov’s into one larger iov, and send the packet along. Would
it be ok to allocate a new buffer, copy the data from the old iovs into
the new one, remove the old buffer from the list of buffers, and then
add the new one? Or do i need to create a new npkt_t with a new buffer
list, register with tx_done, send the new packet, and call tx_done on
the original packet when my tx_done gets called?

The answer is no, you have to alloc_donw_pkt() to get a new npkt,
and copy everything (memcpy_from_npkt()).

On the other hands, if your “modification” didn’t change the packet
length, you should be safe to “modify” orignal data packet, and
recaculate certain checksum.

FYI:
nfm-ipfilter is a filter/NAT module, which modify IP address, tcp/udp
port on both down/up packets. The Source is opened in
http://staff.qnx.com/~xtang/repository

-xtang

Once again. Thanks for the reply.

Well here is a question for you. In the scenario i just
described…allocating a new buffer, copying old iov to new iov, removing old
buffer, adding new buffer to the current packet…can you think of any
reason this would work with the small tcpip stack, but not the large one? I
don’t believe i am modifying the packet length, but this doesn’t work with the
large tcpip stack.

Steve.

Xiaodan Tang wrote:

Steven Erickson <> sojg@mediaone.net> > wrote:
What is the correct way to modify data contained within buffers on the
way down the protocol stack?

For example, say i am a filter driver that sits below the ip layer, and
i want to modify TCP/IP packets on the way down. Assume that there is
only one buffer with mutltiple iov’s attached to the packet. I want to
copy all the iov’s into one larger iov, and send the packet along. Would
it be ok to allocate a new buffer, copy the data from the old iovs into
the new one, remove the old buffer from the list of buffers, and then
add the new one? Or do i need to create a new npkt_t with a new buffer
list, register with tx_done, send the new packet, and call tx_done on
the original packet when my tx_done gets called?

The answer is no, you have to alloc_donw_pkt() to get a new npkt,
and copy everything (memcpy_from_npkt()).

On the other hands, if your “modification” didn’t change the packet
length, you should be safe to “modify” orignal data packet, and
recaculate certain checksum.

FYI:
nfm-ipfilter is a filter/NAT module, which modify IP address, tcp/udp
port on both down/up packets. The Source is opened in
http://staff.qnx.com/~xtang/repository

-xtang

The large stack isn’t expecting the original npkt’s net_but_t list to be
manipulated. For now you have to allocate an entire new packet, copy
the original, call ion->tx_done() on the original, call ion->reg_tx_done
on the new one and send the new one down. Or you can just modify the
data in the original one as Xiaodan mentioned and continue it on its
way.

-seanb

Steven Erickson <sojg@mediaone.net> wrote:
: Once again. Thanks for the reply.

: Well here is a question for you. In the scenario i just
: described…allocating a new buffer, copying old iov to new iov, removing old
: buffer, adding new buffer to the current packet…can you think of any
: reason this would work with the small tcpip stack, but not the large one? I
: don’t believe i am modifying the packet length, but this doesn’t work with the
: large tcpip stack.

: Steve.

: Xiaodan Tang wrote:

:> Steven Erickson <sojg@mediaone.net> wrote:
:> > What is the correct way to modify data contained within buffers on the
:> > way down the protocol stack?
:>
:> > For example, say i am a filter driver that sits below the ip layer, and
:> > i want to modify TCP/IP packets on the way down. Assume that there is
:> > only one buffer with mutltiple iov’s attached to the packet. I want to
:> > copy all the iov’s into one larger iov, and send the packet along. Would
:> > it be ok to allocate a new buffer, copy the data from the old iovs into
:> > the new one, remove the old buffer from the list of buffers, and then
:> > add the new one? Or do i need to create a new npkt_t with a new buffer
:> > list, register with tx_done, send the new packet, and call tx_done on
:> > the original packet when my tx_done gets called?
:>
:> The answer is no, you have to alloc_donw_pkt() to get a new npkt,
:> and copy everything (memcpy_from_npkt()).
:>
:> On the other hands, if your “modification” didn’t change the packet
:> length, you should be safe to “modify” orignal data packet, and
:> recaculate certain checksum.
:>
:> FYI:
:> nfm-ipfilter is a filter/NAT module, which modify IP address, tcp/udp
:> port on both down/up packets. The Source is opened in
:> http://staff.qnx.com/~xtang/repository
:>
:> -xtang

Its working. Thanks to you both.

/Steve.

Sean Boudreau wrote:

The large stack isn’t expecting the original npkt’s net_but_t list to be
manipulated. For now you have to allocate an entire new packet, copy
the original, call ion->tx_done() on the original, call ion->reg_tx_done
on the new one and send the new one down. Or you can just modify the
data in the original one as Xiaodan mentioned and continue it on its
way.

-seanb

Steven Erickson <> sojg@mediaone.net> > wrote:
: Once again. Thanks for the reply.

: Well here is a question for you. In the scenario i just
: described…allocating a new buffer, copying old iov to new iov, removing old
: buffer, adding new buffer to the current packet…can you think of any
: reason this would work with the small tcpip stack, but not the large one? I
: don’t believe i am modifying the packet length, but this doesn’t work with the
: large tcpip stack.

: Steve.

: Xiaodan Tang wrote:

:> Steven Erickson <> sojg@mediaone.net> > wrote:
:> > What is the correct way to modify data contained within buffers on the
:> > way down the protocol stack?
:
:> > For example, say i am a filter driver that sits below the ip layer, and
:> > i want to modify TCP/IP packets on the way down. Assume that there is
:> > only one buffer with mutltiple iov’s attached to the packet. I want to
:> > copy all the iov’s into one larger iov, and send the packet along. Would
:> > it be ok to allocate a new buffer, copy the data from the old iovs into
:> > the new one, remove the old buffer from the list of buffers, and then
:> > add the new one? Or do i need to create a new npkt_t with a new buffer
:> > list, register with tx_done, send the new packet, and call tx_done on
:> > the original packet when my tx_done gets called?
:
:> The answer is no, you have to alloc_donw_pkt() to get a new npkt,
:> and copy everything (memcpy_from_npkt()).
:
:> On the other hands, if your “modification” didn’t change the packet
:> length, you should be safe to “modify” orignal data packet, and
:> recaculate certain checksum.
:
:> FYI:
:> nfm-ipfilter is a filter/NAT module, which modify IP address, tcp/udp
:> port on both down/up packets. The Source is opened in
:> > http://staff.qnx.com/~xtang/repository
:
:> -xtang