From 22a0c4475c91c745f0e5cc1171939359921d09f9 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 27 Aug 2013 16:08:15 +0100 Subject: [ipv4] Generalise fragment reassembly mechanism Generalise the concept of fragment reassembly to allow for code sharing between IPv4 and IPv6 protocols. Signed-off-by: Michael Brown --- src/include/ipxe/fragment.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ src/include/ipxe/ip.h | 12 -------- 2 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/include/ipxe/fragment.h (limited to 'src/include') diff --git a/src/include/ipxe/fragment.h b/src/include/ipxe/fragment.h new file mode 100644 index 000000000..6b47439d5 --- /dev/null +++ b/src/include/ipxe/fragment.h @@ -0,0 +1,68 @@ +#ifndef _IPXE_FRAGMENT_H +#define _IPXE_FRAGMENT_H + +/** @file + * + * Fragment reassembly + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include +#include +#include +#include + +/** Fragment reassembly timeout */ +#define FRAGMENT_TIMEOUT ( TICKS_PER_SEC / 2 ) + +/** A fragment reassembly buffer */ +struct fragment { + /* List of fragment reassembly buffers */ + struct list_head list; + /** Reassembled packet */ + struct io_buffer *iobuf; + /** Length of non-fragmentable portion of reassembled packet */ + size_t hdrlen; + /** Reassembly timer */ + struct retry_timer timer; +}; + +/** A fragment reassembler */ +struct fragment_reassembler { + /** List of fragment reassembly buffers */ + struct list_head list; + /** + * Check if fragment matches fragment reassembly buffer + * + * @v fragment Fragment reassembly buffer + * @v iobuf I/O buffer + * @v hdrlen Length of non-fragmentable potion of I/O buffer + * @ret is_fragment Fragment matches this reassembly buffer + */ + int ( * is_fragment ) ( struct fragment *fragment, + struct io_buffer *iobuf, size_t hdrlen ); + /** + * Get fragment offset + * + * @v iobuf I/O buffer + * @v hdrlen Length of non-fragmentable potion of I/O buffer + * @ret offset Offset + */ + size_t ( * fragment_offset ) ( struct io_buffer *iobuf, size_t hdrlen ); + /** + * Check if more fragments exist + * + * @v iobuf I/O buffer + * @v hdrlen Length of non-fragmentable potion of I/O buffer + * @ret more_frags More fragments exist + */ + int ( * more_fragments ) ( struct io_buffer *iobuf, size_t hdrlen ); +}; + +extern struct io_buffer * +fragment_reassemble ( struct fragment_reassembler *fragments, + struct io_buffer *iobuf, size_t *hdrlen ); + +#endif /* _IPXE_FRAGMENT_H */ diff --git a/src/include/ipxe/ip.h b/src/include/ipxe/ip.h index ca508e274..3234b7b0e 100644 --- a/src/include/ipxe/ip.h +++ b/src/include/ipxe/ip.h @@ -70,18 +70,6 @@ struct ipv4_miniroute { struct in_addr gateway; }; -/* IPv4 fragment reassembly buffer */ -struct ipv4_fragment { - /* List of fragment reassembly buffers */ - struct list_head list; - /** Reassembled packet */ - struct io_buffer *iobuf; - /** Current offset */ - size_t offset; - /** Reassembly timer */ - struct retry_timer timer; -}; - extern struct list_head ipv4_miniroutes; extern struct net_protocol ipv4_protocol __net_protocol; -- cgit v1.2.3-55-g7522