Skip to contentSkip to conversation

NAT handles non-linear skbs

PATCH David S. Miller 2 participants 2 messages May 6, 2003 4 messages not in the archive netfilter

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

I'm starting to Cc' netfilter-devel, since there's nothing secret about this discussion...

Quoted 5 lines · David S. Miller

You should use skb_copy_bits(), and not linearize anything. Not even post IP/tcp/udp headers.

I think you really need to reread the threads where Rusty, Alexey and myself were talking about how this needs to be done.

I don't know what exact thread you are talking about, but I've now re-read the 'De-linearization of conntack' thread.

Quoted 4 lines

Any SKB linearization attempt outside of code that absolutely must mangle the packet is effectively a BUG().

That's the whole point of this exercise.

Doh. Stupid me ;)

Well, if we are going for the copy_bits() solution, we obviously don't want to have every match/target create it's own copy of the bits of data it needs.

Now we have something like:

NF_IP_PRE_ROUTING:

conntrack:
1. ip_conntrack calls tcp_pkt_to_tuple, which calls copy_bits on the first 8 bytes of ip payload
2. ip_conntrack_tcp:tcp_packet copies the full tcp header
3. ip_conntrack_tcp:tcp_new copies the full tcp header
4. ip_conntrack_tcp:tcp_exp_for_matches_paket copies the full tcp header

iptable_mangle (PREROUTING)
- run various matches that would probably want to copy l4 header / payload even if no mangle target is executed (and thus no make_writable() is called later on)

iptable_nat (PREROUTING)
- run various matches that would probably want to copy l4 header / payload even if no nat rule applies (and thus no make_writable() is called later on)

iptable_filter (FORWARD):
- run various matches that would probably want to copy l4 header / payload

(... to be continued...)

We are going to create copies after copies. I don't like that.
What some generic copy-of-packet handler? Some generic code that would
maintain copied bytes of a packet in some buffer associated with the skb?

If we want to make it conntrack-dependent, there could be something like for avery first packet in ESTABLISHED state, we traverse the ruleset, and everybody tells theis copy-manager how many bytes it needs. The resulting maximum value is stored together with the conntrack entry. For every further (ESTABLIHED) packet, the copy manager would then create a copy of <num_stored_in_conntrack> bytes. So we have one-time the on-demand copying, but for all further packets it should be one copy.

This is based on the assumption that all ESTABLISHED packets are treated the same way, which is obviously right for most setups.

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#5 lore raw

From: Harald Welte <[email protected]>
Date: Tue, 6 May 2003 15:16:14 +0200

Well, if we are going for the copy_bits() solution, we obviously don't want to have every match/target create it's own copy of the bits of data it needs.

All the copies go to the local stack, it's really fast.

I think trying to generalize this is a bad idea, the whole value in this whole scaffolding in netfilter is that it can work with anything.

Look at it this way, think about what you'd have to do to pass around "TCP header will be needed". What if all my machine does is UDP stuff :-)