On 2016-08-11 at 00:57:05 +0200, Vadim Kochan <vadi...@gmail.com> wrote:
> Handle 'field_changed' callback to check if IPv4 csum is needed
> to be recalculated, if so - update it on 'packet_update' event.
> 
> Added 'is_csum_valid' to proto_hdr struct to check if csum needs to
> be updated.
> 
> Signed-off-by: Vadim Kochan <vadi...@gmail.com>
> ---
>  trafgen_l3.c    | 33 +++++++++++++++++++++++++++------
>  trafgen_proto.h |  2 ++
>  2 files changed, 29 insertions(+), 6 deletions(-)
> 
> diff --git a/trafgen_l3.c b/trafgen_l3.c
> index 1cdd041..8db7e5d 100644
> --- a/trafgen_l3.c
> +++ b/trafgen_l3.c
> @@ -43,6 +43,30 @@ static void ipv4_header_init(struct proto_hdr *hdr)
>       proto_field_set_default_dev_ipv4(hdr, IP4_SADDR);
>  }
>  
> +static void ipv4_field_changed(struct proto_hdr *hdr, struct proto_field 
> *field)
> +{
> +     hdr->is_csum_valid = false;
> +}
> +
> +static void ipv4_csum_update(struct proto_hdr *hdr)
> +{
> +     struct packet *pkt;
> +     uint16_t csum;
> +
> +     if (proto_field_is_set(hdr, IP4_CSUM))
> +             return;
> +     if (hdr->is_csum_valid)
> +             return;

Minor nit: The check for hdr->is_csum_valid is less expensive and should
come first (in the patch for icmpv4 it's already done like this).

Otherwise the patch looks good.

-- 
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