On Sat, Oct 10, 2020 at 11:58 AM Cong Wang <xiyou.wangc...@gmail.com> wrote: > > On Fri, Oct 9, 2020 at 8:10 PM Xie He <xie.he.0...@gmail.com> wrote: > > > > This seems so weird to me. If a user is using an AF_PACKET/RAW socket, > > the user is supposed to do what the header_ops->create function does > > (that is, creating two headers and leaving two holes to be filled in > > later). I think no user would actually do that. That is so weird. > > Well, AF_PACKET RAW socket is supposed to construct L2 headers > from the user buffer, and for a tunnel device these headers are indeed its > L2. If users do not want to do this, they can switch to DGRAM anyway. > > I know how inconvenient it is to construct a GRE tunnel header, I guess > this is why all other tunnel devices do not provide a header_ops::create. > GRE tunnel is not a special case, this is why I agree on removing its > ->create() although it does look like all tunnel devices should let users > construct headers by definition of RAW. > > Of course, it may be too late to change this behavior even if we really > want, users may already assume there is always no tunnel header needed > to construct.
Another reason why tunnel devices usually don't provide header_ops->create might be to keep consistency with TAP devices. TAP devices are just like tunnel (TUN) devices except that they use an additional Ethernet header after the tunnel headers. I guess that TAP devices would usually use Ethernet's header_ops to expose only the Ethernet header to the user, but hide the outer tunnel headers from the user and let them be constructed on the transmission path (so that TAP devices would appear exactly like Ethernet devices). If we want to keep TUN devices consistent with TAP devices, we should hide the tunnel headers from the user for TUN devices, too. Actually, a lot of devices expose a fake L2 header in header_ops, instead of their real L2 header anyway. Wi-Fi devices usually pretend to be Ethernet devices and expose an Ethernet header in header_ops. So I think it is acceptable to not expose the real L2 header in header_ops. (This is also what needed_headroom is created for - to request additional header space for headers not exposed in header_ops.)