On 2016-08-11 at 20:11:02 +0200, Vadim Kochan <vadi...@gmail.com> wrote:
> On Thu, Aug 11, 2016 at 06:16:27PM +0200, Tobias Klauser wrote:
> > Currently struct proto_hdr is used twofold:
> > 
> >   1) Statically define protocol behavior, i.e. all the *_hdr definitions in
> >      trafgen_l{2,3,4}.c which map a protocol id/layer to a set of callback
> >      functions.
> > 
> >   2) For each packet created at parse time the struct is memcpy()'ed
> >      (including all the static information from 1) and then used to store
> >      dynamic information at parse/run time.
> > 
> > Thus, struct proto_hdr members such as the proto id, layer and the
> > pointers callback functions get copied for each created packet (in
> > addition to the other fields which get changed during parsing). Also,
> > static/dynamic information get mixed and we e.g. can't make the protocol
> > definitions const to ensure they'll not get changed by mistake.
> > 
> > Rather than copying the struct proto_hdr for every packet, clearly
> > separate the two purposes defined above by splitting struct proto_hdr
> > into two structs:
> > 
> >   1) struct proto_ops for the static (const) protocol behavior definition
> > 
> >   2) struct proto_hdr (reduced) for dynamic information
> > 
> > struct proto_hdr keeps a pointer to the corresponding proto_ops instance
> > and uses it to execute the corresponding callbacks.
> 
> You can add my "Acked-by" if it is needed.

Thanks, will add it to the final patch.

> > 
> > Reference: 
> > https://groups.google.com/forum/#!msg/netsniff-ng/20RvwJdh50Y/eMkbmKSaBgAJ
> > Signed-off-by: Tobias Klauser <tklau...@distanz.ch>
> > ---
> >  trafgen_l2.c     | 24 ++++++++++-----------
> >  trafgen_l3.c     |  8 +++----
> >  trafgen_l4.c     | 22 +++++++++----------
> >  trafgen_parser.y |  2 +-
> >  trafgen_proto.c  | 65 
> > +++++++++++++++++++++++++++++---------------------------
> >  trafgen_proto.h  | 40 +++++++++++++++++-----------------
> >  6 files changed, 83 insertions(+), 78 deletions(-)
> > 
> > diff --git a/trafgen_l2.c b/trafgen_l2.c
> > index 1863332b3543..f09b2a61cacc 100644
> > --- a/trafgen_l2.c
> > +++ b/trafgen_l2.c
> > @@ -47,7 +47,7 @@ static void eth_header_init(struct proto_hdr *hdr)
> >     proto_field_set_default_dev_mac(hdr, ETH_SRC_ADDR);
> >  }
> >  
> >  
> > -struct proto_hdr *proto_header_init(enum proto_id pid)
> > +struct proto_hdr *proto_header_new(enum proto_id pid)
> 
> The old name was really bad by may be something like:
> 
>     {proto,packet}_header_{add,push}
> 
> might be better ?

I agree, renamed it to proto_header_push.

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to