Browse Source

[xferbuf] Add xfer_buffer() to provide direct access to underlying buffer

Allow data transfer buffer users to provide direct access to their
underlying data transfer buffer.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
07b0d4fa30
2 changed files with 44 additions and 0 deletions
  1. 39
    0
      src/core/xferbuf.c
  2. 5
    0
      src/include/ipxe/xferbuf.h

+ 39
- 0
src/core/xferbuf.c View File

283
 	.write = xferbuf_umalloc_write,
283
 	.write = xferbuf_umalloc_write,
284
 	.read = xferbuf_umalloc_read,
284
 	.read = xferbuf_umalloc_read,
285
 };
285
 };
286
+
287
+/**
288
+ * Get underlying data transfer buffer
289
+ *
290
+ * @v interface		Data transfer interface
291
+ * @ret xferbuf		Data transfer buffer, or NULL on error
292
+ *
293
+ * This call will check that the xfer_buffer() handler belongs to the
294
+ * destination interface which also provides xfer_deliver() for this
295
+ * interface.
296
+ *
297
+ * This is done to prevent accidental accesses to a data transfer
298
+ * buffer which may be located behind a non-transparent datapath via a
299
+ * series of pass-through interfaces.
300
+ */
301
+struct xfer_buffer * xfer_buffer ( struct interface *intf ) {
302
+	struct interface *dest;
303
+	xfer_buffer_TYPE ( void * ) *op =
304
+		intf_get_dest_op ( intf, xfer_buffer, &dest );
305
+	void *object = intf_object ( dest );
306
+	struct interface *xfer_deliver_dest;
307
+	struct xfer_buffer *xferbuf;
308
+
309
+	/* Check that this operation is provided by the same interface
310
+	 * which handles xfer_deliver().
311
+	 */
312
+	intf_get_dest_op ( intf, xfer_deliver, &xfer_deliver_dest );
313
+
314
+	if ( op && ( dest == xfer_deliver_dest ) ) {
315
+		xferbuf = op ( object );
316
+	} else {
317
+		/* Default is to not have a data transfer buffer */
318
+		xferbuf = NULL;
319
+	}
320
+
321
+	intf_put ( xfer_deliver_dest );
322
+	intf_put ( dest );
323
+	return xferbuf;
324
+}

+ 5
- 0
src/include/ipxe/xferbuf.h View File

12
 #include <stdint.h>
12
 #include <stdint.h>
13
 #include <ipxe/iobuf.h>
13
 #include <ipxe/iobuf.h>
14
 #include <ipxe/uaccess.h>
14
 #include <ipxe/uaccess.h>
15
+#include <ipxe/interface.h>
15
 #include <ipxe/xfer.h>
16
 #include <ipxe/xfer.h>
16
 
17
 
17
 /** A data transfer buffer */
18
 /** A data transfer buffer */
97
 			     struct io_buffer *iobuf,
98
 			     struct io_buffer *iobuf,
98
 			     struct xfer_metadata *meta );
99
 			     struct xfer_metadata *meta );
99
 
100
 
101
+extern struct xfer_buffer * xfer_buffer ( struct interface *intf );
102
+#define xfer_buffer_TYPE( object_type ) \
103
+	typeof ( struct xfer_buffer * ( object_type ) )
104
+
100
 #endif /* _IPXE_XFERBUF_H */
105
 #endif /* _IPXE_XFERBUF_H */

Loading…
Cancel
Save