On 17/05/17 17:13, David Miller wrote: > Both cases are common in real BPF programs. The offsets really are > necessary. It's funny because initially I tried to implement this > without the auxiliary offset and it simply doesn't work. :-) > > We always have to track when you've seen the offset that cancels out > the NET_IP_ALIGN. And as stated it can occur both before and after > variable offsets have been introduced. > > You have to catch both: > > ptr += variable; > ptr += 14; > > and: > > ptr += 14; > ptr += variable; /* align = 4 */ > > And always see at the end that "NET_IP_ALIGN + offsets" will > be properly 4 byte aligned.
Did you see the algorithms I posted with two masks? Effectively they are tracking the 'quotient' and 'remainder', but in a was that might be easier to manipulate (bit-twiddly etc.) than the aux offset. I think they handle both the above cases, in a nicely general way. -Ed