Browse Source

[interface] Convert all data-xfer interfaces to generic interfaces

Remove data-xfer as an interface type, and replace data-xfer
interfaces with generic interfaces supporting the data-xfer methods.

Filter interfaces (as used by the TLS layer) are handled using the
generic pass-through interface capability.  A side-effect of this is
that deliver_raw() no longer exists as a data-xfer method.  (In
practice this doesn't lose any efficiency, since there are no
instances within the current codebase where xfer_deliver_raw() is used
to pass data to an interface supporting the deliver_raw() method.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
4327d5d39f

+ 42
- 50
src/arch/i386/interface/pxe/pxe_tftp.c View File

31
 #include <ipxe/uaccess.h>
31
 #include <ipxe/uaccess.h>
32
 #include <ipxe/in.h>
32
 #include <ipxe/in.h>
33
 #include <ipxe/tftp.h>
33
 #include <ipxe/tftp.h>
34
+#include <ipxe/iobuf.h>
34
 #include <ipxe/xfer.h>
35
 #include <ipxe/xfer.h>
35
 #include <ipxe/open.h>
36
 #include <ipxe/open.h>
36
 #include <ipxe/process.h>
37
 #include <ipxe/process.h>
39
 /** A PXE TFTP connection */
40
 /** A PXE TFTP connection */
40
 struct pxe_tftp_connection {
41
 struct pxe_tftp_connection {
41
 	/** Data transfer interface */
42
 	/** Data transfer interface */
42
-	struct xfer_interface xfer;
43
+	struct interface xfer;
43
 	/** Data buffer */
44
 	/** Data buffer */
44
 	userptr_t buffer;
45
 	userptr_t buffer;
45
 	/** Size of data buffer */
46
 	/** Size of data buffer */
58
 	int rc;
59
 	int rc;
59
 };
60
 };
60
 
61
 
61
-/** The PXE TFTP connection */
62
-static struct pxe_tftp_connection pxe_tftp = {
63
-	.xfer = XFER_INIT ( &null_xfer_ops ),
64
-};
65
-
66
 /**
62
 /**
67
  * Close PXE TFTP connection
63
  * Close PXE TFTP connection
68
  *
64
  *
65
+ * @v pxe_tftp		PXE TFTP connection
69
  * @v rc		Final status code
66
  * @v rc		Final status code
70
  */
67
  */
71
-static void pxe_tftp_close ( int rc ) {
72
-	xfer_nullify ( &pxe_tftp.xfer );
73
-	xfer_close ( &pxe_tftp.xfer, rc );
74
-	pxe_tftp.rc = rc;
68
+static void pxe_tftp_close ( struct pxe_tftp_connection *pxe_tftp, int rc ) {
69
+	intf_shutdown ( &pxe_tftp->xfer, rc );
70
+	pxe_tftp->rc = rc;
75
 }
71
 }
76
 
72
 
77
 /**
73
 /**
78
  * Receive new data
74
  * Receive new data
79
  *
75
  *
80
- * @v xfer		Data transfer interface
76
+ * @v pxe_tftp		PXE TFTP connection
81
  * @v iobuf		I/O buffer
77
  * @v iobuf		I/O buffer
82
  * @v meta		Transfer metadata
78
  * @v meta		Transfer metadata
83
  * @ret rc		Return status code
79
  * @ret rc		Return status code
84
  */
80
  */
85
-static int pxe_tftp_xfer_deliver_iob ( struct xfer_interface *xfer __unused,
86
-				       struct io_buffer *iobuf,
87
-				       struct xfer_metadata *meta ) {
81
+static int pxe_tftp_xfer_deliver ( struct pxe_tftp_connection *pxe_tftp,
82
+				   struct io_buffer *iobuf,
83
+				   struct xfer_metadata *meta ) {
88
 	size_t len = iob_len ( iobuf );
84
 	size_t len = iob_len ( iobuf );
89
 	int rc = 0;
85
 	int rc = 0;
90
 
86
 
91
 	/* Calculate new buffer position */
87
 	/* Calculate new buffer position */
92
 	if ( meta->whence != SEEK_CUR )
88
 	if ( meta->whence != SEEK_CUR )
93
-		pxe_tftp.offset = 0;
94
-	pxe_tftp.offset += meta->offset;
89
+		pxe_tftp->offset = 0;
90
+	pxe_tftp->offset += meta->offset;
95
 
91
 
96
 	/* Copy data block to buffer */
92
 	/* Copy data block to buffer */
97
 	if ( len == 0 ) {
93
 	if ( len == 0 ) {
98
 		/* No data (pure seek); treat as success */
94
 		/* No data (pure seek); treat as success */
99
-	} else if ( pxe_tftp.offset < pxe_tftp.start ) {
95
+	} else if ( pxe_tftp->offset < pxe_tftp->start ) {
100
 		DBG ( " buffer underrun at %zx (min %zx)",
96
 		DBG ( " buffer underrun at %zx (min %zx)",
101
-		      pxe_tftp.offset, pxe_tftp.start );
97
+		      pxe_tftp->offset, pxe_tftp->start );
102
 		rc = -ENOBUFS;
98
 		rc = -ENOBUFS;
103
-	} else if ( ( pxe_tftp.offset + len ) >
104
-		    ( pxe_tftp.start + pxe_tftp.size ) ) {
99
+	} else if ( ( pxe_tftp->offset + len ) >
100
+		    ( pxe_tftp->start + pxe_tftp->size ) ) {
105
 		DBG ( " buffer overrun at %zx (max %zx)",
101
 		DBG ( " buffer overrun at %zx (max %zx)",
106
-		      ( pxe_tftp.offset + len ),
107
-		      ( pxe_tftp.start + pxe_tftp.size ) );
102
+		      ( pxe_tftp->offset + len ),
103
+		      ( pxe_tftp->start + pxe_tftp->size ) );
108
 		rc = -ENOBUFS;
104
 		rc = -ENOBUFS;
109
 	} else {
105
 	} else {
110
-		copy_to_user ( pxe_tftp.buffer,
111
-			       ( pxe_tftp.offset - pxe_tftp.start ),
106
+		copy_to_user ( pxe_tftp->buffer,
107
+			       ( pxe_tftp->offset - pxe_tftp->start ),
112
 			       iobuf->data, len );
108
 			       iobuf->data, len );
113
 	}
109
 	}
114
 
110
 
115
 	/* Calculate new buffer position */
111
 	/* Calculate new buffer position */
116
-	pxe_tftp.offset += len;
112
+	pxe_tftp->offset += len;
117
 
113
 
118
 	/* Record maximum offset as the file size */
114
 	/* Record maximum offset as the file size */
119
-	if ( pxe_tftp.max_offset < pxe_tftp.offset )
120
-		pxe_tftp.max_offset = pxe_tftp.offset;
115
+	if ( pxe_tftp->max_offset < pxe_tftp->offset )
116
+		pxe_tftp->max_offset = pxe_tftp->offset;
121
 
117
 
122
 	/* Terminate transfer on error */
118
 	/* Terminate transfer on error */
123
 	if ( rc != 0 )
119
 	if ( rc != 0 )
124
-		pxe_tftp_close ( rc );
120
+		pxe_tftp_close ( pxe_tftp, rc );
125
 
121
 
126
 	free_iob ( iobuf );
122
 	free_iob ( iobuf );
127
 	return rc;
123
 	return rc;
128
 }
124
 }
129
 
125
 
130
-/**
131
- * Handle close() event
132
- *
133
- * @v xfer		Data transfer interface
134
- * @v rc		Reason for close
135
- */
136
-static void pxe_tftp_xfer_close ( struct xfer_interface *xfer __unused,
137
-				  int rc ) {
138
-	pxe_tftp_close ( rc );
139
-}
126
+/** PXE TFTP connection interface operations */
127
+static struct interface_operation pxe_tftp_xfer_ops[] = {
128
+	INTF_OP ( xfer_deliver, struct pxe_tftp_connection *,
129
+		  pxe_tftp_xfer_deliver ),
130
+	INTF_OP ( intf_close, struct pxe_tftp_connection *, pxe_tftp_close ),
131
+};
140
 
132
 
141
-static struct xfer_interface_operations pxe_tftp_xfer_ops = {
142
-	.close		= pxe_tftp_xfer_close,
143
-	.vredirect	= xfer_vreopen,
144
-	.window		= unlimited_xfer_window,
145
-	.alloc_iob	= default_xfer_alloc_iob,
146
-	.deliver_iob	= pxe_tftp_xfer_deliver_iob,
147
-	.deliver_raw	= xfer_deliver_as_iob,
133
+/** PXE TFTP connection interface descriptor */
134
+static struct interface_descriptor pxe_tftp_xfer_desc =
135
+	INTF_DESC ( struct pxe_tftp_connection, xfer, pxe_tftp_xfer_ops );
136
+
137
+/** The PXE TFTP connection */
138
+static struct pxe_tftp_connection pxe_tftp = {
139
+	.xfer = INTF_INIT ( pxe_tftp_xfer_desc ),
148
 };
140
 };
149
 
141
 
150
 /**
142
 /**
173
 
165
 
174
 	/* Reset PXE TFTP connection structure */
166
 	/* Reset PXE TFTP connection structure */
175
 	memset ( &pxe_tftp, 0, sizeof ( pxe_tftp ) );
167
 	memset ( &pxe_tftp, 0, sizeof ( pxe_tftp ) );
176
-	xfer_init ( &pxe_tftp.xfer, &pxe_tftp_xfer_ops, NULL );
168
+	intf_init ( &pxe_tftp.xfer, &pxe_tftp_xfer_desc, NULL );
177
 	pxe_tftp.rc = -EINPROGRESS;
169
 	pxe_tftp.rc = -EINPROGRESS;
178
 
170
 
179
 	/* Construct URI string */
171
 	/* Construct URI string */
247
 	DBG ( "PXENV_TFTP_OPEN" );
239
 	DBG ( "PXENV_TFTP_OPEN" );
248
 
240
 
249
 	/* Guard against callers that fail to close before re-opening */
241
 	/* Guard against callers that fail to close before re-opening */
250
-	pxe_tftp_close ( 0 );
242
+	pxe_tftp_close ( &pxe_tftp, 0 );
251
 
243
 
252
 	/* Open connection */
244
 	/* Open connection */
253
 	if ( ( rc = pxe_tftp_open ( tftp_open->ServerIPAddress,
245
 	if ( ( rc = pxe_tftp_open ( tftp_open->ServerIPAddress,
296
 PXENV_EXIT_t pxenv_tftp_close ( struct s_PXENV_TFTP_CLOSE *tftp_close ) {
288
 PXENV_EXIT_t pxenv_tftp_close ( struct s_PXENV_TFTP_CLOSE *tftp_close ) {
297
 	DBG ( "PXENV_TFTP_CLOSE" );
289
 	DBG ( "PXENV_TFTP_CLOSE" );
298
 
290
 
299
-	pxe_tftp_close ( 0 );
291
+	pxe_tftp_close ( &pxe_tftp, 0 );
300
 	tftp_close->Status = PXENV_STATUS_SUCCESS;
292
 	tftp_close->Status = PXENV_STATUS_SUCCESS;
301
 	return PXENV_EXIT_SUCCESS;
293
 	return PXENV_EXIT_SUCCESS;
302
 }
294
 }
491
 	tftp_read_file->BufferSize = pxe_tftp.max_offset;
483
 	tftp_read_file->BufferSize = pxe_tftp.max_offset;
492
 
484
 
493
 	/* Close TFTP file */
485
 	/* Close TFTP file */
494
-	pxe_tftp_close ( rc );
486
+	pxe_tftp_close ( &pxe_tftp, rc );
495
 
487
 
496
 	tftp_read_file->Status = PXENV_STATUS ( rc );
488
 	tftp_read_file->Status = PXENV_STATUS ( rc );
497
 	return ( rc ? PXENV_EXIT_FAILURE : PXENV_EXIT_SUCCESS );
489
 	return ( rc ? PXENV_EXIT_FAILURE : PXENV_EXIT_SUCCESS );
565
 		rc = 0;
557
 		rc = 0;
566
 
558
 
567
 	/* Close TFTP file */
559
 	/* Close TFTP file */
568
-	pxe_tftp_close ( rc );
560
+	pxe_tftp_close ( &pxe_tftp, rc );
569
 
561
 
570
 	tftp_get_fsize->Status = PXENV_STATUS ( rc );
562
 	tftp_get_fsize->Status = PXENV_STATUS ( rc );
571
 	return ( rc ? PXENV_EXIT_FAILURE : PXENV_EXIT_SUCCESS );
563
 	return ( rc ? PXENV_EXIT_FAILURE : PXENV_EXIT_SUCCESS );

+ 16
- 19
src/arch/i386/interface/pxe/pxe_udp.c View File

6
 
6
 
7
 #include <string.h>
7
 #include <string.h>
8
 #include <byteswap.h>
8
 #include <byteswap.h>
9
+#include <ipxe/iobuf.h>
9
 #include <ipxe/xfer.h>
10
 #include <ipxe/xfer.h>
10
 #include <ipxe/udp.h>
11
 #include <ipxe/udp.h>
11
 #include <ipxe/uaccess.h>
12
 #include <ipxe/uaccess.h>
35
 /** A PXE UDP connection */
36
 /** A PXE UDP connection */
36
 struct pxe_udp_connection {
37
 struct pxe_udp_connection {
37
 	/** Data transfer interface to UDP stack */
38
 	/** Data transfer interface to UDP stack */
38
-	struct xfer_interface xfer;
39
+	struct interface xfer;
39
 	/** Local address */
40
 	/** Local address */
40
 	struct sockaddr_in local;
41
 	struct sockaddr_in local;
41
 	/** Current PXENV_UDP_READ parameter block */
42
 	/** Current PXENV_UDP_READ parameter block */
45
 /**
46
 /**
46
  * Receive PXE UDP data
47
  * Receive PXE UDP data
47
  *
48
  *
48
- * @v xfer			Data transfer interface
49
+ * @v pxe_udp			PXE UDP connection
49
  * @v iobuf			I/O buffer
50
  * @v iobuf			I/O buffer
50
  * @v meta			Data transfer metadata
51
  * @v meta			Data transfer metadata
51
  * @ret rc			Return status code
52
  * @ret rc			Return status code
53
  * Receives a packet as part of the current pxenv_udp_read()
54
  * Receives a packet as part of the current pxenv_udp_read()
54
  * operation.
55
  * operation.
55
  */
56
  */
56
-static int pxe_udp_deliver_iob ( struct xfer_interface *xfer,
57
-				 struct io_buffer *iobuf,
58
-				 struct xfer_metadata *meta ) {
59
-	struct pxe_udp_connection *pxe_udp = 
60
-		container_of ( xfer, struct pxe_udp_connection, xfer );
57
+static int pxe_udp_deliver ( struct pxe_udp_connection *pxe_udp,
58
+			     struct io_buffer *iobuf,
59
+			     struct xfer_metadata *meta ) {
61
 	struct s_PXENV_UDP_READ *pxenv_udp_read = pxe_udp->pxenv_udp_read;
60
 	struct s_PXENV_UDP_READ *pxenv_udp_read = pxe_udp->pxenv_udp_read;
62
 	struct sockaddr_in *sin_src;
61
 	struct sockaddr_in *sin_src;
63
 	struct sockaddr_in *sin_dest;
62
 	struct sockaddr_in *sin_dest;
102
 }
101
 }
103
 
102
 
104
 /** PXE UDP data transfer interface operations */
103
 /** PXE UDP data transfer interface operations */
105
-static struct xfer_interface_operations pxe_udp_xfer_operations = {
106
-	.close		= ignore_xfer_close,
107
-	.vredirect	= ignore_xfer_vredirect,
108
-	.window		= unlimited_xfer_window,
109
-	.alloc_iob	= default_xfer_alloc_iob,
110
-	.deliver_iob	= pxe_udp_deliver_iob,
111
-	.deliver_raw	= xfer_deliver_as_iob,
104
+static struct interface_operation pxe_udp_xfer_operations[] = {
105
+	INTF_OP ( xfer_deliver, struct pxe_udp_connection *, pxe_udp_deliver ),
112
 };
106
 };
113
 
107
 
108
+/** PXE UDP data transfer interface descriptor */
109
+static struct interface_descriptor pxe_udp_xfer_desc =
110
+	INTF_DESC ( struct pxe_udp_connection, xfer, pxe_udp_xfer_operations );
111
+
114
 /** The PXE UDP connection */
112
 /** The PXE UDP connection */
115
 static struct pxe_udp_connection pxe_udp = {
113
 static struct pxe_udp_connection pxe_udp = {
116
-	.xfer = XFER_INIT ( &pxe_udp_xfer_operations ),
114
+	.xfer = INTF_INIT ( pxe_udp_xfer_desc ),
117
 	.local = {
115
 	.local = {
118
 		.sin_family = AF_INET,
116
 		.sin_family = AF_INET,
119
 	},
117
 	},
171
 	DBG ( " %s", inet_ntoa ( pxe_udp.local.sin_addr ) );
169
 	DBG ( " %s", inet_ntoa ( pxe_udp.local.sin_addr ) );
172
 
170
 
173
 	/* Open promiscuous UDP connection */
171
 	/* Open promiscuous UDP connection */
174
-	xfer_close ( &pxe_udp.xfer, 0 );
172
+	intf_restart ( &pxe_udp.xfer, 0 );
175
 	if ( ( rc = udp_open_promisc ( &pxe_udp.xfer ) ) != 0 ) {
173
 	if ( ( rc = udp_open_promisc ( &pxe_udp.xfer ) ) != 0 ) {
176
 		pxenv_udp_open->Status = PXENV_STATUS ( rc );
174
 		pxenv_udp_open->Status = PXENV_STATUS ( rc );
177
 		return PXENV_EXIT_FAILURE;
175
 		return PXENV_EXIT_FAILURE;
206
 	DBG ( "PXENV_UDP_CLOSE" );
204
 	DBG ( "PXENV_UDP_CLOSE" );
207
 
205
 
208
 	/* Close UDP connection */
206
 	/* Close UDP connection */
209
-	xfer_close ( &pxe_udp.xfer, 0 );
207
+	intf_restart ( &pxe_udp.xfer, 0 );
210
 
208
 
211
 	pxenv_udp_close->Status = PXENV_STATUS_SUCCESS;
209
 	pxenv_udp_close->Status = PXENV_STATUS_SUCCESS;
212
 	return PXENV_EXIT_SUCCESS;
210
 	return PXENV_EXIT_SUCCESS;
304
 	      ntohs ( pxenv_udp_write->dst_port ) );
302
 	      ntohs ( pxenv_udp_write->dst_port ) );
305
 	
303
 	
306
 	/* Transmit packet */
304
 	/* Transmit packet */
307
-	if ( ( rc = xfer_deliver_iob_meta ( &pxe_udp.xfer, iobuf,
308
-					    &meta ) ) != 0 ) {
305
+	if ( ( rc = xfer_deliver ( &pxe_udp.xfer, iobuf, &meta ) ) != 0 ) {
309
 		pxenv_udp_write->Status = PXENV_STATUS ( rc );
306
 		pxenv_udp_write->Status = PXENV_STATUS ( rc );
310
 		return PXENV_EXIT_FAILURE;
307
 		return PXENV_EXIT_FAILURE;
311
 	}
308
 	}

+ 16
- 32
src/core/downloader.c View File

21
 #include <stdlib.h>
21
 #include <stdlib.h>
22
 #include <stdarg.h>
22
 #include <stdarg.h>
23
 #include <errno.h>
23
 #include <errno.h>
24
+#include <ipxe/iobuf.h>
24
 #include <ipxe/xfer.h>
25
 #include <ipxe/xfer.h>
25
 #include <ipxe/open.h>
26
 #include <ipxe/open.h>
26
 #include <ipxe/job.h>
27
 #include <ipxe/job.h>
43
 	/** Job control interface */
44
 	/** Job control interface */
44
 	struct interface job;
45
 	struct interface job;
45
 	/** Data transfer interface */
46
 	/** Data transfer interface */
46
-	struct xfer_interface xfer;
47
+	struct interface xfer;
47
 
48
 
48
 	/** Image to contain downloaded file */
49
 	/** Image to contain downloaded file */
49
 	struct image *image;
50
 	struct image *image;
79
 		rc = downloader->register_image ( downloader->image );
80
 		rc = downloader->register_image ( downloader->image );
80
 
81
 
81
 	/* Shut down interfaces */
82
 	/* Shut down interfaces */
82
-	xfer_nullify ( &downloader->xfer );
83
-	xfer_close ( &downloader->xfer, rc );
83
+	intf_shutdown ( &downloader->xfer, rc );
84
 	intf_shutdown ( &downloader->job, rc );
84
 	intf_shutdown ( &downloader->job, rc );
85
 }
85
 }
86
 
86
 
145
  */
145
  */
146
 
146
 
147
 /**
147
 /**
148
- * Handle deliver_raw() event received via data transfer interface
148
+ * Handle received data
149
  *
149
  *
150
- * @v xfer		Downloader data transfer interface
150
+ * @v downloader	Downloader
151
  * @v iobuf		Datagram I/O buffer
151
  * @v iobuf		Datagram I/O buffer
152
  * @v meta		Data transfer metadata
152
  * @v meta		Data transfer metadata
153
  * @ret rc		Return status code
153
  * @ret rc		Return status code
154
  */
154
  */
155
-static int downloader_xfer_deliver_iob ( struct xfer_interface *xfer,
156
-					 struct io_buffer *iobuf,
157
-					 struct xfer_metadata *meta ) {
158
-	struct downloader *downloader =
159
-		container_of ( xfer, struct downloader, xfer );
155
+static int downloader_xfer_deliver ( struct downloader *downloader,
156
+				     struct io_buffer *iobuf,
157
+				     struct xfer_metadata *meta ) {
160
 	size_t len;
158
 	size_t len;
161
 	size_t max;
159
 	size_t max;
162
 	int rc;
160
 	int rc;
184
 	return rc;
182
 	return rc;
185
 }
183
 }
186
 
184
 
187
-/**
188
- * Handle close() event received via data transfer interface
189
- *
190
- * @v xfer		Downloader data transfer interface
191
- * @v rc		Reason for close
192
- */
193
-static void downloader_xfer_close ( struct xfer_interface *xfer, int rc ) {
194
-	struct downloader *downloader =
195
-		container_of ( xfer, struct downloader, xfer );
196
-
197
-	/* Terminate download */
198
-	downloader_finished ( downloader, rc );
199
-}
200
-
201
 /** Downloader data transfer interface operations */
185
 /** Downloader data transfer interface operations */
202
-static struct xfer_interface_operations downloader_xfer_operations = {
203
-	.close		= downloader_xfer_close,
204
-	.vredirect	= xfer_vreopen,
205
-	.window		= unlimited_xfer_window,
206
-	.alloc_iob	= default_xfer_alloc_iob,
207
-	.deliver_iob	= downloader_xfer_deliver_iob,
208
-	.deliver_raw	= xfer_deliver_as_iob,
186
+static struct interface_operation downloader_xfer_operations[] = {
187
+	INTF_OP ( xfer_deliver, struct downloader *, downloader_xfer_deliver ),
188
+	INTF_OP ( intf_close, struct downloader *, downloader_finished ),
209
 };
189
 };
210
 
190
 
191
+/** Downloader data transfer interface descriptor */
192
+static struct interface_descriptor downloader_xfer_desc =
193
+	INTF_DESC ( struct downloader, xfer, downloader_xfer_operations );
194
+
211
 /****************************************************************************
195
 /****************************************************************************
212
  *
196
  *
213
  * Job control interface
197
  * Job control interface
258
 	ref_init ( &downloader->refcnt, downloader_free );
242
 	ref_init ( &downloader->refcnt, downloader_free );
259
 	intf_init ( &downloader->job, &downloader_job_desc,
243
 	intf_init ( &downloader->job, &downloader_job_desc,
260
 		    &downloader->refcnt );
244
 		    &downloader->refcnt );
261
-	xfer_init ( &downloader->xfer, &downloader_xfer_operations,
245
+	intf_init ( &downloader->xfer, &downloader_xfer_desc,
262
 		    &downloader->refcnt );
246
 		    &downloader->refcnt );
263
 	downloader->image = image_get ( image );
247
 	downloader->image = image_get ( image );
264
 	downloader->register_image = register_image;
248
 	downloader->register_image = register_image;

+ 0
- 74
src/core/filter.c View File

1
-/*
2
- * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2 of the
7
- * License, or any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
- */
18
-
19
-FILE_LICENCE ( GPL2_OR_LATER );
20
-
21
-#include <ipxe/xfer.h>
22
-#include <ipxe/filter.h>
23
-
24
-/** @file
25
- *
26
- * Data transfer filters
27
- *
28
- */
29
-
30
-/*
31
- * Pass-through methods to be used by filters which don't want to
32
- * intercept all events.
33
- *
34
- */
35
-
36
-void filter_close ( struct xfer_interface *xfer, int rc ) {
37
-	struct xfer_interface *other = filter_other_half ( xfer );
38
-
39
-	xfer_close ( other, rc );
40
-}
41
-
42
-int filter_vredirect ( struct xfer_interface *xfer, int type,
43
-			va_list args ) {
44
-	struct xfer_interface *other = filter_other_half ( xfer );
45
-
46
-	return xfer_vredirect ( other, type, args );
47
-}
48
-
49
-size_t filter_window ( struct xfer_interface *xfer ) {
50
-	struct xfer_interface *other = filter_other_half ( xfer );
51
-
52
-	return xfer_window ( other );
53
-}
54
-
55
-struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
56
-				      size_t len ) {
57
-	struct xfer_interface *other = filter_other_half ( xfer );
58
-
59
-	return xfer_alloc_iob ( other, len );
60
-}
61
-
62
-int filter_deliver_iob ( struct xfer_interface *xfer, struct io_buffer *iobuf,
63
-			 struct xfer_metadata *meta ) {
64
-	struct xfer_interface *other = filter_other_half ( xfer );
65
-
66
-	return xfer_deliver_iob_meta ( other, iobuf, meta );
67
-}
68
-
69
-int filter_deliver_raw ( struct xfer_interface *xfer, const void *data,
70
-			 size_t len ) {
71
-	struct xfer_interface *other = filter_other_half ( xfer );
72
-
73
-	return xfer_deliver_raw ( other, data, len );
74
-}

+ 10
- 19
src/core/hw.c View File

15
 
15
 
16
 struct hw {
16
 struct hw {
17
 	struct refcnt refcnt;
17
 	struct refcnt refcnt;
18
-	struct xfer_interface xfer;
18
+	struct interface xfer;
19
 	struct process process;
19
 	struct process process;
20
 };
20
 };
21
 
21
 
22
 static const char hw_msg[] = "Hello world!\n";
22
 static const char hw_msg[] = "Hello world!\n";
23
 
23
 
24
 static void hw_finished ( struct hw *hw, int rc ) {
24
 static void hw_finished ( struct hw *hw, int rc ) {
25
-	xfer_nullify ( &hw->xfer );
26
-	xfer_close ( &hw->xfer, rc );
25
+	intf_shutdown ( &hw->xfer, rc );
27
 	process_del ( &hw->process );
26
 	process_del ( &hw->process );
28
 }
27
 }
29
 
28
 
30
-static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
31
-	struct hw *hw = container_of ( xfer, struct hw, xfer );
32
-
33
-	hw_finished ( hw, rc );
34
-}
35
-
36
-static struct xfer_interface_operations hw_xfer_operations = {
37
-	.close		= hw_xfer_close,
38
-	.vredirect	= ignore_xfer_vredirect,
39
-	.window		= unlimited_xfer_window,
40
-	.alloc_iob	= default_xfer_alloc_iob,
41
-	.deliver_iob	= xfer_deliver_as_raw,
42
-	.deliver_raw	= ignore_xfer_deliver_raw,
29
+static struct interface_operation hw_xfer_operations[] = {
30
+	INTF_OP ( intf_close, struct hw *, hw_finished ),
43
 };
31
 };
44
 
32
 
33
+static struct interface_descriptor hw_xfer_desc =
34
+	INTF_DESC ( struct hw, xfer, hw_xfer_operations );
35
+
45
 static void hw_step ( struct process *process ) {
36
 static void hw_step ( struct process *process ) {
46
 	struct hw *hw = container_of ( process, struct hw, process );
37
 	struct hw *hw = container_of ( process, struct hw, process );
47
 	int rc;
38
 	int rc;
52
 	}
43
 	}
53
 }
44
 }
54
 
45
 
55
-static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
46
+static int hw_open ( struct interface *xfer, struct uri *uri __unused ) {
56
 	struct hw *hw;
47
 	struct hw *hw;
57
 
48
 
58
 	/* Allocate and initialise structure */
49
 	/* Allocate and initialise structure */
60
 	if ( ! hw )
51
 	if ( ! hw )
61
 		return -ENOMEM;
52
 		return -ENOMEM;
62
 	ref_init ( &hw->refcnt, NULL );
53
 	ref_init ( &hw->refcnt, NULL );
63
-	xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
54
+	intf_init ( &hw->xfer, &hw_xfer_desc, &hw->refcnt );
64
 	process_init ( &hw->process, hw_step, &hw->refcnt );
55
 	process_init ( &hw->process, hw_step, &hw->refcnt );
65
 
56
 
66
 	/* Attach parent interface, mortalise self, and return */
57
 	/* Attach parent interface, mortalise self, and return */
67
-	xfer_plug_plug ( &hw->xfer, xfer );
58
+	intf_plug_plug ( &hw->xfer, xfer );
68
 	ref_put ( &hw->refcnt );
59
 	ref_put ( &hw->refcnt );
69
 	return 0;
60
 	return 0;
70
 }
61
 }

+ 37
- 32
src/core/open.c View File

35
 /**
35
 /**
36
  * Open URI
36
  * Open URI
37
  *
37
  *
38
- * @v xfer		Data transfer interface
38
+ * @v intf		Data transfer interface
39
  * @v uri		URI
39
  * @v uri		URI
40
  * @ret rc		Return status code
40
  * @ret rc		Return status code
41
  *
41
  *
42
  * The URI will be regarded as being relative to the current working
42
  * The URI will be regarded as being relative to the current working
43
  * URI (see churi()).
43
  * URI (see churi()).
44
  */
44
  */
45
-int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
45
+int xfer_open_uri ( struct interface *intf, struct uri *uri ) {
46
 	struct uri_opener *opener;
46
 	struct uri_opener *opener;
47
 	struct uri *resolved_uri;
47
 	struct uri *resolved_uri;
48
 	int rc = -ENOTSUP;
48
 	int rc = -ENOTSUP;
55
 	/* Find opener which supports this URI scheme */
55
 	/* Find opener which supports this URI scheme */
56
 	for_each_table_entry ( opener, URI_OPENERS ) {
56
 	for_each_table_entry ( opener, URI_OPENERS ) {
57
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
57
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
58
-			DBGC ( xfer, "XFER %p opening %s URI\n",
59
-			       xfer, opener->scheme );
60
-			rc = opener->open ( xfer, resolved_uri );
58
+			DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT
59
+			       " opening %s URI\n", INTF_DBG ( intf ),
60
+			       resolved_uri->scheme );
61
+			rc = opener->open ( intf, resolved_uri );
61
 			goto done;
62
 			goto done;
62
 		}
63
 		}
63
 	}
64
 	}
64
-	DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
65
-	       "\"%s\"\n", xfer, resolved_uri->scheme );
65
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
66
+	       "unsupported URI scheme \"%s\"\n",
67
+	       INTF_DBG ( intf ), resolved_uri->scheme );
66
 
68
 
67
  done:
69
  done:
68
 	uri_put ( resolved_uri );
70
 	uri_put ( resolved_uri );
72
 /**
74
 /**
73
  * Open URI string
75
  * Open URI string
74
  *
76
  *
75
- * @v xfer		Data transfer interface
77
+ * @v intf		Data transfer interface
76
  * @v uri_string	URI string (e.g. "http://ipxe.org/kernel")
78
  * @v uri_string	URI string (e.g. "http://ipxe.org/kernel")
77
  * @ret rc		Return status code
79
  * @ret rc		Return status code
78
  *
80
  *
79
  * The URI will be regarded as being relative to the current working
81
  * The URI will be regarded as being relative to the current working
80
  * URI (see churi()).
82
  * URI (see churi()).
81
  */
83
  */
82
-int xfer_open_uri_string ( struct xfer_interface *xfer,
84
+int xfer_open_uri_string ( struct interface *intf,
83
 			   const char *uri_string ) {
85
 			   const char *uri_string ) {
84
 	struct uri *uri;
86
 	struct uri *uri;
85
 	int rc;
87
 	int rc;
86
 
88
 
87
-	DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
89
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening URI %s\n",
90
+	       INTF_DBG ( intf ), uri_string );
88
 
91
 
89
 	uri = parse_uri ( uri_string );
92
 	uri = parse_uri ( uri_string );
90
 	if ( ! uri )
93
 	if ( ! uri )
91
 		return -ENOMEM;
94
 		return -ENOMEM;
92
 
95
 
93
-	rc = xfer_open_uri ( xfer, uri );
96
+	rc = xfer_open_uri ( intf, uri );
94
 
97
 
95
 	uri_put ( uri );
98
 	uri_put ( uri );
96
 	return rc;
99
 	return rc;
99
 /**
102
 /**
100
  * Open socket
103
  * Open socket
101
  *
104
  *
102
- * @v xfer		Data transfer interface
105
+ * @v intf		Data transfer interface
103
  * @v semantics		Communication semantics (e.g. SOCK_STREAM)
106
  * @v semantics		Communication semantics (e.g. SOCK_STREAM)
104
  * @v peer		Peer socket address
107
  * @v peer		Peer socket address
105
  * @v local		Local socket address, or NULL
108
  * @v local		Local socket address, or NULL
106
  * @ret rc		Return status code
109
  * @ret rc		Return status code
107
  */
110
  */
108
-int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
111
+int xfer_open_socket ( struct interface *intf, int semantics,
109
 		       struct sockaddr *peer, struct sockaddr *local ) {
112
 		       struct sockaddr *peer, struct sockaddr *local ) {
110
 	struct socket_opener *opener;
113
 	struct socket_opener *opener;
111
 
114
 
112
-	DBGC ( xfer, "XFER %p opening (%s,%s) socket\n", xfer,
113
-	       socket_semantics_name ( semantics ),
115
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening (%s,%s) socket\n",
116
+	       INTF_DBG ( intf ), socket_semantics_name ( semantics ),
114
 	       socket_family_name ( peer->sa_family ) );
117
 	       socket_family_name ( peer->sa_family ) );
115
 
118
 
116
 	for_each_table_entry ( opener, SOCKET_OPENERS ) {
119
 	for_each_table_entry ( opener, SOCKET_OPENERS ) {
117
 		if ( ( opener->semantics == semantics ) &&
120
 		if ( ( opener->semantics == semantics ) &&
118
 		     ( opener->family == peer->sa_family ) ) {
121
 		     ( opener->family == peer->sa_family ) ) {
119
-			return opener->open ( xfer, peer, local );
122
+			return opener->open ( intf, peer, local );
120
 		}
123
 		}
121
 	}
124
 	}
122
 
125
 
123
-	DBGC ( xfer, "XFER %p attempted to open unsupported socket type "
124
-	       "(%s,%s)\n", xfer, socket_semantics_name ( semantics ),
126
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
127
+	       "unsupported socket type (%s,%s)\n",
128
+	       INTF_DBG ( intf ), socket_semantics_name ( semantics ),
125
 	       socket_family_name ( peer->sa_family ) );
129
 	       socket_family_name ( peer->sa_family ) );
126
 	return -ENOTSUP;
130
 	return -ENOTSUP;
127
 }
131
 }
129
 /**
133
 /**
130
  * Open location
134
  * Open location
131
  *
135
  *
132
- * @v xfer		Data transfer interface
136
+ * @v intf		Data transfer interface
133
  * @v type		Location type
137
  * @v type		Location type
134
  * @v args		Remaining arguments depend upon location type
138
  * @v args		Remaining arguments depend upon location type
135
  * @ret rc		Return status code
139
  * @ret rc		Return status code
136
  */
140
  */
137
-int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args ) {
141
+int xfer_vopen ( struct interface *intf, int type, va_list args ) {
138
 	switch ( type ) {
142
 	switch ( type ) {
139
 	case LOCATION_URI_STRING: {
143
 	case LOCATION_URI_STRING: {
140
 		const char *uri_string = va_arg ( args, const char * );
144
 		const char *uri_string = va_arg ( args, const char * );
141
 
145
 
142
-		return xfer_open_uri_string ( xfer, uri_string ); }
146
+		return xfer_open_uri_string ( intf, uri_string ); }
143
 	case LOCATION_URI: {
147
 	case LOCATION_URI: {
144
 		struct uri *uri = va_arg ( args, struct uri * );
148
 		struct uri *uri = va_arg ( args, struct uri * );
145
 
149
 
146
-		return xfer_open_uri ( xfer, uri ); }
150
+		return xfer_open_uri ( intf, uri ); }
147
 	case LOCATION_SOCKET: {
151
 	case LOCATION_SOCKET: {
148
 		int semantics = va_arg ( args, int );
152
 		int semantics = va_arg ( args, int );
149
 		struct sockaddr *peer = va_arg ( args, struct sockaddr * );
153
 		struct sockaddr *peer = va_arg ( args, struct sockaddr * );
150
 		struct sockaddr *local = va_arg ( args, struct sockaddr * );
154
 		struct sockaddr *local = va_arg ( args, struct sockaddr * );
151
 
155
 
152
-		return xfer_open_socket ( xfer, semantics, peer, local ); }
156
+		return xfer_open_socket ( intf, semantics, peer, local ); }
153
 	default:
157
 	default:
154
-		DBGC ( xfer, "XFER %p attempted to open unsupported location "
155
-		       "type %d\n", xfer, type );
158
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to "
159
+		       "open unsupported location type %d\n",
160
+		       INTF_DBG ( intf ), type );
156
 		return -ENOTSUP;
161
 		return -ENOTSUP;
157
 	}
162
 	}
158
 }
163
 }
160
 /**
165
 /**
161
  * Open location
166
  * Open location
162
  *
167
  *
163
- * @v xfer		Data transfer interface
168
+ * @v intf		Data transfer interface
164
  * @v type		Location type
169
  * @v type		Location type
165
  * @v ...		Remaining arguments depend upon location type
170
  * @v ...		Remaining arguments depend upon location type
166
  * @ret rc		Return status code
171
  * @ret rc		Return status code
167
  */
172
  */
168
-int xfer_open ( struct xfer_interface *xfer, int type, ... ) {
173
+int xfer_open ( struct interface *intf, int type, ... ) {
169
 	va_list args;
174
 	va_list args;
170
 	int rc;
175
 	int rc;
171
 
176
 
172
 	va_start ( args, type );
177
 	va_start ( args, type );
173
-	rc = xfer_vopen ( xfer, type, args );
178
+	rc = xfer_vopen ( intf, type, args );
174
 	va_end ( args );
179
 	va_end ( args );
175
 	return rc;
180
 	return rc;
176
 }
181
 }
178
 /**
183
 /**
179
  * Reopen location
184
  * Reopen location
180
  *
185
  *
181
- * @v xfer		Data transfer interface
186
+ * @v intf		Data transfer interface
182
  * @v type		Location type
187
  * @v type		Location type
183
  * @v args		Remaining arguments depend upon location type
188
  * @v args		Remaining arguments depend upon location type
184
  * @ret rc		Return status code
189
  * @ret rc		Return status code
187
  * using xfer_vopen().  It is intended to be used as a .vredirect
192
  * using xfer_vopen().  It is intended to be used as a .vredirect
188
  * method handler.
193
  * method handler.
189
  */
194
  */
190
-int xfer_vreopen ( struct xfer_interface *xfer, int type, va_list args ) {
195
+int xfer_vreopen ( struct interface *intf, int type, va_list args ) {
191
 
196
 
192
 	/* Close existing connection */
197
 	/* Close existing connection */
193
-	xfer_close ( xfer, 0 );
198
+	intf_restart ( intf, 0 );
194
 
199
 
195
 	/* Open new location */
200
 	/* Open new location */
196
-	return xfer_vopen ( xfer, type, args );
201
+	return xfer_vopen ( intf, type, args );
197
 }
202
 }

+ 15
- 32
src/core/posix_io.c View File

22
 #include <string.h>
22
 #include <string.h>
23
 #include <errno.h>
23
 #include <errno.h>
24
 #include <ipxe/list.h>
24
 #include <ipxe/list.h>
25
+#include <ipxe/iobuf.h>
25
 #include <ipxe/xfer.h>
26
 #include <ipxe/xfer.h>
26
 #include <ipxe/open.h>
27
 #include <ipxe/open.h>
27
 #include <ipxe/process.h>
28
 #include <ipxe/process.h>
50
 	 */
51
 	 */
51
 	int rc;
52
 	int rc;
52
 	/** Data transfer interface */
53
 	/** Data transfer interface */
53
-	struct xfer_interface xfer;
54
+	struct interface xfer;
54
 	/** Current seek position */
55
 	/** Current seek position */
55
 	size_t pos;
56
 	size_t pos;
56
 	/** File size */
57
 	/** File size */
87
  * @v rc		Reason for termination
88
  * @v rc		Reason for termination
88
  */
89
  */
89
 static void posix_file_finished ( struct posix_file *file, int rc ) {
90
 static void posix_file_finished ( struct posix_file *file, int rc ) {
90
-	xfer_nullify ( &file->xfer );
91
-	xfer_close ( &file->xfer, rc );
91
+	intf_shutdown ( &file->xfer, rc );
92
 	file->rc = rc;
92
 	file->rc = rc;
93
 }
93
 }
94
 
94
 
95
-/**
96
- * Handle close() event
97
- *
98
- * @v xfer		POSIX file data transfer interface
99
- * @v rc		Reason for close
100
- */
101
-static void posix_file_xfer_close ( struct xfer_interface *xfer, int rc ) {
102
-	struct posix_file *file =
103
-		container_of ( xfer, struct posix_file, xfer );
104
-
105
-	posix_file_finished ( file, rc );
106
-}
107
-
108
 /**
95
 /**
109
  * Handle deliver_iob() event
96
  * Handle deliver_iob() event
110
  *
97
  *
111
- * @v xfer		POSIX file data transfer interface
98
+ * @v file		POSIX file
112
  * @v iobuf		I/O buffer
99
  * @v iobuf		I/O buffer
113
  * @v meta		Data transfer metadata
100
  * @v meta		Data transfer metadata
114
  * @ret rc		Return status code
101
  * @ret rc		Return status code
115
  */
102
  */
116
-static int
117
-posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
118
-			      struct io_buffer *iobuf,
119
-			      struct xfer_metadata *meta ) {
120
-	struct posix_file *file =
121
-		container_of ( xfer, struct posix_file, xfer );
103
+static int posix_file_xfer_deliver ( struct posix_file *file,
104
+				     struct io_buffer *iobuf,
105
+				     struct xfer_metadata *meta ) {
122
 
106
 
123
 	/* Keep track of file position solely for the filesize */
107
 	/* Keep track of file position solely for the filesize */
124
 	if ( meta->whence != SEEK_CUR )
108
 	if ( meta->whence != SEEK_CUR )
137
 }
121
 }
138
 
122
 
139
 /** POSIX file data transfer interface operations */
123
 /** POSIX file data transfer interface operations */
140
-static struct xfer_interface_operations posix_file_xfer_operations = {
141
-	.close		= posix_file_xfer_close,
142
-	.vredirect	= xfer_vreopen,
143
-	.window		= unlimited_xfer_window,
144
-	.alloc_iob	= default_xfer_alloc_iob,
145
-	.deliver_iob	= posix_file_xfer_deliver_iob,
146
-	.deliver_raw	= xfer_deliver_as_iob,
124
+static struct interface_operation posix_file_xfer_operations[] = {
125
+	INTF_OP ( xfer_deliver, struct posix_file *, posix_file_xfer_deliver ),
126
+	INTF_OP ( intf_close, struct posix_file *, posix_file_finished ),
147
 };
127
 };
148
 
128
 
129
+/** POSIX file data transfer interface descriptor */
130
+static struct interface_descriptor posix_file_xfer_desc =
131
+	INTF_DESC ( struct posix_file, xfer, posix_file_xfer_operations );
132
+
149
 /**
133
 /**
150
  * Identify file by file descriptor
134
  * Identify file by file descriptor
151
  *
135
  *
201
 	ref_init ( &file->refcnt, posix_file_free );
185
 	ref_init ( &file->refcnt, posix_file_free );
202
 	file->fd = fd;
186
 	file->fd = fd;
203
 	file->rc = -EINPROGRESS;
187
 	file->rc = -EINPROGRESS;
204
-	xfer_init ( &file->xfer, &posix_file_xfer_operations,
205
-		    &file->refcnt );
188
+	intf_init ( &file->xfer, &posix_file_xfer_desc, &file->refcnt );
206
 	INIT_LIST_HEAD ( &file->data );
189
 	INIT_LIST_HEAD ( &file->data );
207
 
190
 
208
 	/* Open URI on data transfer interface */
191
 	/* Open URI on data transfer interface */

+ 20
- 23
src/core/resolv.c View File

299
 	/** Reference counter */
299
 	/** Reference counter */
300
 	struct refcnt refcnt;
300
 	struct refcnt refcnt;
301
 	/** Data transfer interface */
301
 	/** Data transfer interface */
302
-	struct xfer_interface xfer;
302
+	struct interface xfer;
303
 	/** Name resolution interface */
303
 	/** Name resolution interface */
304
 	struct interface resolv;
304
 	struct interface resolv;
305
 	/** Communication semantics (e.g. SOCK_STREAM) */
305
 	/** Communication semantics (e.g. SOCK_STREAM) */
319
 static void named_close ( struct named_socket *named, int rc ) {
319
 static void named_close ( struct named_socket *named, int rc ) {
320
 	/* Shut down interfaces */
320
 	/* Shut down interfaces */
321
 	intf_shutdown ( &named->resolv, rc );
321
 	intf_shutdown ( &named->resolv, rc );
322
-	xfer_nullify ( &named->xfer );
323
-	xfer_close ( &named->xfer, rc );
322
+	intf_shutdown ( &named->xfer, rc );
324
 }
323
 }
325
 
324
 
326
 /**
325
 /**
327
- * Handle close() event
326
+ * Check flow control window
328
  *
327
  *
329
- * @v xfer		Data transfer interface
330
- * @v rc		Reason for close
328
+ * @v named		Named socket
329
+ * @ret len		Length of window
331
  */
330
  */
332
-static void named_xfer_close ( struct xfer_interface *xfer, int rc ) {
333
-	struct named_socket *named =
334
-		container_of ( xfer, struct named_socket, xfer );
335
-
336
-	named_close ( named, rc );
331
+static size_t named_window ( struct named_socket *named __unused ) {
332
+	/* Not ready for data until we have redirected away */
333
+	return 0;
337
 }
334
 }
338
 
335
 
339
 /** Named socket opener data transfer interface operations */
336
 /** Named socket opener data transfer interface operations */
340
-static struct xfer_interface_operations named_xfer_ops = {
341
-	.close		= named_xfer_close,
342
-	.vredirect	= ignore_xfer_vredirect,
343
-	.window		= no_xfer_window,
344
-	.alloc_iob	= default_xfer_alloc_iob,
345
-	.deliver_iob	= xfer_deliver_as_raw,
346
-	.deliver_raw	= ignore_xfer_deliver_raw,
337
+static struct interface_operation named_xfer_ops[] = {
338
+	INTF_OP ( xfer_window, struct named_socket *, named_window ),
339
+	INTF_OP ( intf_close, struct named_socket *, named_close ),
347
 };
340
 };
348
 
341
 
342
+/** Named socket opener data transfer interface descriptor */
343
+static struct interface_descriptor named_xfer_desc =
344
+	INTF_DESC ( struct named_socket, xfer, named_xfer_ops );
345
+
349
 /**
346
 /**
350
  * Name resolved
347
  * Name resolved
351
  *
348
  *
357
 	int rc;
354
 	int rc;
358
 
355
 
359
 	/* Nullify data transfer interface */
356
 	/* Nullify data transfer interface */
360
-	xfer_nullify ( &named->xfer );
357
+	intf_nullify ( &named->xfer );
361
 
358
 
362
 	/* Redirect data-xfer interface */
359
 	/* Redirect data-xfer interface */
363
 	if ( ( rc = xfer_redirect ( &named->xfer, LOCATION_SOCKET,
360
 	if ( ( rc = xfer_redirect ( &named->xfer, LOCATION_SOCKET,
370
 	} else {
367
 	} else {
371
 		/* Redirection succeeded - unplug data-xfer interface */
368
 		/* Redirection succeeded - unplug data-xfer interface */
372
 		DBGC ( named, "NAMED %p redirected successfully\n", named );
369
 		DBGC ( named, "NAMED %p redirected successfully\n", named );
373
-		xfer_unplug ( &named->xfer );
370
+		intf_unplug ( &named->xfer );
374
 	}
371
 	}
375
 
372
 
376
 	/* Terminate named socket opener */
373
 	/* Terminate named socket opener */
396
  * @v local		Local socket address, or NULL
393
  * @v local		Local socket address, or NULL
397
  * @ret rc		Return status code
394
  * @ret rc		Return status code
398
  */
395
  */
399
-int xfer_open_named_socket ( struct xfer_interface *xfer, int semantics,
396
+int xfer_open_named_socket ( struct interface *xfer, int semantics,
400
 			     struct sockaddr *peer, const char *name,
397
 			     struct sockaddr *peer, const char *name,
401
 			     struct sockaddr *local ) {
398
 			     struct sockaddr *local ) {
402
 	struct named_socket *named;
399
 	struct named_socket *named;
407
 	if ( ! named )
404
 	if ( ! named )
408
 		return -ENOMEM;
405
 		return -ENOMEM;
409
 	ref_init ( &named->refcnt, NULL );
406
 	ref_init ( &named->refcnt, NULL );
410
-	xfer_init ( &named->xfer, &named_xfer_ops, &named->refcnt );
407
+	intf_init ( &named->xfer, &named_xfer_desc, &named->refcnt );
411
 	intf_init ( &named->resolv, &named_resolv_desc, &named->refcnt );
408
 	intf_init ( &named->resolv, &named_resolv_desc, &named->refcnt );
412
 	named->semantics = semantics;
409
 	named->semantics = semantics;
413
 	if ( local ) {
410
 	if ( local ) {
423
 		goto err;
420
 		goto err;
424
 
421
 
425
 	/* Attach parent interface, mortalise self, and return */
422
 	/* Attach parent interface, mortalise self, and return */
426
-	xfer_plug_plug ( &named->xfer, xfer );
423
+	intf_plug_plug ( &named->xfer, xfer );
427
 	ref_put ( &named->refcnt );
424
 	ref_put ( &named->refcnt );
428
 	return 0;
425
 	return 0;
429
 
426
 

+ 126
- 245
src/core/xfer.c View File

21
 #include <string.h>
21
 #include <string.h>
22
 #include <stdio.h>
22
 #include <stdio.h>
23
 #include <errno.h>
23
 #include <errno.h>
24
+#include <ipxe/iobuf.h>
24
 #include <ipxe/xfer.h>
25
 #include <ipxe/xfer.h>
26
+#include <ipxe/open.h>
25
 
27
 
26
 /** @file
28
 /** @file
27
  *
29
  *
37
  */
39
  */
38
 static struct xfer_metadata dummy_metadata;
40
 static struct xfer_metadata dummy_metadata;
39
 
41
 
40
-/**
41
- * Close data transfer interface
42
+/*****************************************************************************
43
+ *
44
+ * Data transfer interface operations
42
  *
45
  *
43
- * @v xfer		Data transfer interface
44
- * @v rc		Reason for close
45
  */
46
  */
46
-void xfer_close ( struct xfer_interface *xfer, int rc ) {
47
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
48
-	struct xfer_interface_operations *op = xfer->op;
49
-
50
-	DBGC ( xfer, "XFER %p->%p close\n", xfer, dest );
51
-
52
-	xfer_unplug ( xfer );
53
-	xfer_nullify ( xfer );
54
-	dest->op->close ( dest, rc );
55
-	xfer->op = op;
56
-	xfer_put ( dest );
57
-}
58
 
47
 
59
 /**
48
 /**
60
  * Send redirection event
49
  * Send redirection event
61
  *
50
  *
62
- * @v xfer		Data transfer interface
51
+ * @v intf		Data transfer interface
63
  * @v type		New location type
52
  * @v type		New location type
64
  * @v args		Remaining arguments depend upon location type
53
  * @v args		Remaining arguments depend upon location type
65
  * @ret rc		Return status code
54
  * @ret rc		Return status code
66
  */
55
  */
67
-int xfer_vredirect ( struct xfer_interface *xfer, int type, va_list args ) {
68
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
56
+int xfer_vredirect ( struct interface *intf, int type, va_list args ) {
57
+	struct interface *dest;
58
+	xfer_vredirect_TYPE ( void * ) *op =
59
+		intf_get_dest_op ( intf, xfer_vredirect, &dest );
60
+	void *object = intf_object ( dest );
69
 	int rc;
61
 	int rc;
70
 
62
 
71
-	DBGC ( xfer, "XFER %p->%p redirect\n", xfer, dest );
63
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect\n",
64
+	       INTF_INTF_DBG ( intf, dest ) );
72
 
65
 
73
-	rc = dest->op->vredirect ( dest, type, args );
66
+	if ( op ) {
67
+		rc = op ( object, type, args );
68
+	} else {
69
+		/* Default is to reopen the interface as instructed */
70
+		rc = xfer_vreopen ( dest, type, args );
71
+	}
74
 
72
 
75
 	if ( rc != 0 ) {
73
 	if ( rc != 0 ) {
76
-		DBGC ( xfer, "XFER %p<-%p redirect: %s\n", xfer, dest,
74
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect "
75
+		       "failed: %s\n", INTF_INTF_DBG ( intf, dest ),
77
 		       strerror ( rc ) );
76
 		       strerror ( rc ) );
78
 	}
77
 	}
79
-	xfer_put ( dest );
80
-	return rc;
81
-}
82
 
78
 
83
-/**
84
- * Send redirection event
85
- *
86
- * @v xfer		Data transfer interface
87
- * @v type		New location type
88
- * @v ...		Remaining arguments depend upon location type
89
- * @ret rc		Return status code
90
- */
91
-int xfer_redirect ( struct xfer_interface *xfer, int type, ... ) {
92
-	va_list args;
93
-	int rc;
94
-
95
-	va_start ( args, type );
96
-	rc = xfer_vredirect ( xfer, type, args );
97
-	va_end ( args );
79
+	intf_put ( dest );
98
 	return rc;
80
 	return rc;
99
 }
81
 }
100
 
82
 
101
 /**
83
 /**
102
  * Check flow control window
84
  * Check flow control window
103
  *
85
  *
104
- * @v xfer		Data transfer interface
86
+ * @v intf		Data transfer interface
105
  * @ret len		Length of window
87
  * @ret len		Length of window
106
  */
88
  */
107
-size_t xfer_window ( struct xfer_interface *xfer ) {
108
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
89
+size_t xfer_window ( struct interface *intf ) {
90
+	struct interface *dest;
91
+	xfer_window_TYPE ( void * ) *op =
92
+		intf_get_dest_op ( intf, xfer_window, &dest );
93
+	void *object = intf_object ( dest );
109
 	size_t len;
94
 	size_t len;
110
 
95
 
111
-	len = dest->op->window ( dest );
96
+	if ( op ) {
97
+		len = op ( object );
98
+	} else {
99
+		/* Default is to provide an unlimited window */
100
+		len = ~( ( size_t ) 0 );
101
+	}
112
 
102
 
113
-	xfer_put ( dest );
103
+	intf_put ( dest );
114
 	return len;
104
 	return len;
115
 }
105
 }
116
 
106
 
117
 /**
107
 /**
118
  * Allocate I/O buffer
108
  * Allocate I/O buffer
119
  *
109
  *
120
- * @v xfer		Data transfer interface
110
+ * @v intf		Data transfer interface
121
  * @v len		I/O buffer payload length
111
  * @v len		I/O buffer payload length
122
  * @ret iobuf		I/O buffer
112
  * @ret iobuf		I/O buffer
123
  */
113
  */
124
-struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer, size_t len ) {
125
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
114
+struct io_buffer * xfer_alloc_iob ( struct interface *intf, size_t len ) {
115
+	struct interface *dest;
116
+	xfer_alloc_iob_TYPE ( void * ) *op =
117
+		intf_get_dest_op ( intf, xfer_alloc_iob, &dest );
118
+	void *object = intf_object ( dest );
126
 	struct io_buffer *iobuf;
119
 	struct io_buffer *iobuf;
127
 
120
 
128
-	DBGC ( xfer, "XFER %p->%p alloc_iob %zd\n", xfer, dest, len );
121
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob %zd\n",
122
+	       INTF_INTF_DBG ( intf, dest ), len );
129
 
123
 
130
-	iobuf = dest->op->alloc_iob ( dest, len );
124
+	if ( op ) {
125
+		iobuf = op ( object, len );
126
+	} else {
127
+		/* Default is to allocate an I/O buffer with no
128
+		 * reserved space.
129
+		 */
130
+		iobuf = alloc_iob ( len );
131
+	}
131
 
132
 
132
 	if ( ! iobuf ) {
133
 	if ( ! iobuf ) {
133
-		DBGC ( xfer, "XFER %p<-%p alloc_iob failed\n", xfer, dest );
134
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob "
135
+		       "failed\n", INTF_INTF_DBG ( intf, dest ) );
134
 	}
136
 	}
135
-	xfer_put ( dest );
137
+
138
+	intf_put ( dest );
136
 	return iobuf;
139
 	return iobuf;
137
 }
140
 }
138
 
141
 
139
 /**
142
 /**
140
- * Deliver datagram as I/O buffer with metadata
143
+ * Deliver datagram
141
  *
144
  *
142
- * @v xfer		Data transfer interface
145
+ * @v intf		Data transfer interface
143
  * @v iobuf		Datagram I/O buffer
146
  * @v iobuf		Datagram I/O buffer
144
  * @v meta		Data transfer metadata
147
  * @v meta		Data transfer metadata
145
  * @ret rc		Return status code
148
  * @ret rc		Return status code
146
  */
149
  */
147
-int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
148
-			    struct io_buffer *iobuf,
149
-			    struct xfer_metadata *meta ) {
150
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
150
+int xfer_deliver ( struct interface *intf,
151
+		   struct io_buffer *iobuf,
152
+		   struct xfer_metadata *meta ) {
153
+	struct interface *dest;
154
+	xfer_deliver_TYPE ( void * ) *op =
155
+		intf_get_dest_op ( intf, xfer_deliver, &dest );
156
+	void *object = intf_object ( dest );
151
 	int rc;
157
 	int rc;
152
 
158
 
153
-	DBGC ( xfer, "XFER %p->%p deliver_iob %zd\n", xfer, dest,
154
-	       iob_len ( iobuf ) );
159
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " deliver %zd\n",
160
+	       INTF_INTF_DBG ( intf, dest ), iob_len ( iobuf ) );
155
 
161
 
156
-	rc = dest->op->deliver_iob ( dest, iobuf, meta );
162
+	if ( op ) {
163
+		rc = op ( object, iobuf, meta );
164
+	} else {
165
+		/* Default is to discard the I/O buffer */
166
+		free_iob ( iobuf );
167
+		rc = -EPIPE;
168
+	}
157
 
169
 
158
 	if ( rc != 0 ) {
170
 	if ( rc != 0 ) {
159
-		DBGC ( xfer, "XFER %p<-%p deliver_iob: %s\n", xfer, dest,
160
-		       strerror ( rc ) );
171
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT
172
+		       " deliver failed: %s\n",
173
+		       INTF_INTF_DBG ( intf, dest ), strerror ( rc ) );
161
 	}
174
 	}
162
-	xfer_put ( dest );
175
+
176
+	intf_put ( dest );
177
+	return rc;
178
+}
179
+
180
+/*****************************************************************************
181
+ *
182
+ * Data transfer interface helper functions
183
+ *
184
+ */
185
+
186
+/**
187
+ * Send redirection event
188
+ *
189
+ * @v intf		Data transfer interface
190
+ * @v type		New location type
191
+ * @v ...		Remaining arguments depend upon location type
192
+ * @ret rc		Return status code
193
+ */
194
+int xfer_redirect ( struct interface *intf, int type, ... ) {
195
+	va_list args;
196
+	int rc;
197
+
198
+	va_start ( args, type );
199
+	rc = xfer_vredirect ( intf, type, args );
200
+	va_end ( args );
163
 	return rc;
201
 	return rc;
164
 }
202
 }
165
 
203
 
166
 /**
204
 /**
167
- * Deliver datagram as I/O buffer with metadata
205
+ * Deliver datagram as I/O buffer without metadata
168
  *
206
  *
169
- * @v xfer		Data transfer interface
207
+ * @v intf		Data transfer interface
170
  * @v iobuf		Datagram I/O buffer
208
  * @v iobuf		Datagram I/O buffer
171
  * @ret rc		Return status code
209
  * @ret rc		Return status code
172
  */
210
  */
173
-int xfer_deliver_iob ( struct xfer_interface *xfer,
174
-		       struct io_buffer *iobuf ) {
175
-	return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
211
+int xfer_deliver_iob ( struct interface *intf, struct io_buffer *iobuf ) {
212
+	return xfer_deliver ( intf, iobuf, &dummy_metadata );
176
 }
213
 }
177
 
214
 
178
 /**
215
 /**
179
  * Deliver datagram as raw data
216
  * Deliver datagram as raw data
180
  *
217
  *
181
- * @v xfer		Data transfer interface
218
+ * @v intf		Data transfer interface
182
  * @v iobuf		Datagram I/O buffer
219
  * @v iobuf		Datagram I/O buffer
183
  * @ret rc		Return status code
220
  * @ret rc		Return status code
184
  */
221
  */
185
-int xfer_deliver_raw ( struct xfer_interface *xfer,
186
-		       const void *data, size_t len ) {
187
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
188
-	int rc;
189
-
190
-	DBGC ( xfer, "XFER %p->%p deliver_raw %p+%zd\n", xfer, dest,
191
-	       data, len );
222
+int xfer_deliver_raw ( struct interface *intf, const void *data, size_t len ) {
223
+	struct io_buffer *iobuf;
192
 
224
 
193
-	rc = dest->op->deliver_raw ( dest, data, len );
225
+	iobuf = xfer_alloc_iob ( intf, len );
226
+	if ( ! iobuf )
227
+		return -ENOMEM;
194
 
228
 
195
-	if ( rc != 0 ) {
196
-		DBGC ( xfer, "XFER %p<-%p deliver_raw: %s\n", xfer, dest,
197
-		       strerror ( rc ) );
198
-	}
199
-	xfer_put ( dest );
200
-	return rc;
229
+	memcpy ( iob_put ( iobuf, len ), data, len );
230
+	return xfer_deliver_iob ( intf, iobuf );
201
 }
231
 }
202
 
232
 
203
 /**
233
 /**
204
  * Deliver formatted string
234
  * Deliver formatted string
205
  *
235
  *
206
- * @v xfer		Data transfer interface
236
+ * @v intf		Data transfer interface
207
  * @v format		Format string
237
  * @v format		Format string
208
  * @v args		Arguments corresponding to the format string
238
  * @v args		Arguments corresponding to the format string
209
  * @ret rc		Return status code
239
  * @ret rc		Return status code
210
  */
240
  */
211
-int xfer_vprintf ( struct xfer_interface *xfer, const char *format,
241
+int xfer_vprintf ( struct interface *intf, const char *format,
212
 		   va_list args ) {
242
 		   va_list args ) {
213
 	size_t len;
243
 	size_t len;
214
 	va_list args_tmp;
244
 	va_list args_tmp;
219
 		char buf[len + 1];
249
 		char buf[len + 1];
220
 		vsnprintf ( buf, sizeof ( buf ), format, args_tmp );
250
 		vsnprintf ( buf, sizeof ( buf ), format, args_tmp );
221
 		va_end ( args_tmp );
251
 		va_end ( args_tmp );
222
-		return xfer_deliver_raw ( xfer, buf, len );
252
+		return xfer_deliver_raw ( intf, buf, len );
223
 	}
253
 	}
224
 }
254
 }
225
 
255
 
226
 /**
256
 /**
227
  * Deliver formatted string
257
  * Deliver formatted string
228
  *
258
  *
229
- * @v xfer		Data transfer interface
259
+ * @v intf		Data transfer interface
230
  * @v format		Format string
260
  * @v format		Format string
231
  * @v ...		Arguments corresponding to the format string
261
  * @v ...		Arguments corresponding to the format string
232
  * @ret rc		Return status code
262
  * @ret rc		Return status code
233
  */
263
  */
234
-int xfer_printf ( struct xfer_interface *xfer, const char *format, ... ) {
264
+int xfer_printf ( struct interface *intf, const char *format, ... ) {
235
 	va_list args;
265
 	va_list args;
236
 	int rc;
266
 	int rc;
237
 
267
 
238
 	va_start ( args, format );
268
 	va_start ( args, format );
239
-	rc = xfer_vprintf ( xfer, format, args );
269
+	rc = xfer_vprintf ( intf, format, args );
240
 	va_end ( args );
270
 	va_end ( args );
241
 	return rc;
271
 	return rc;
242
 }
272
 }
244
 /**
274
 /**
245
  * Seek to position
275
  * Seek to position
246
  *
276
  *
247
- * @v xfer		Data transfer interface
277
+ * @v intf		Data transfer interface
248
  * @v offset		Offset to new position
278
  * @v offset		Offset to new position
249
  * @v whence		Basis for new position
279
  * @v whence		Basis for new position
250
  * @ret rc		Return status code
280
  * @ret rc		Return status code
251
  */
281
  */
252
-int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence ) {
282
+int xfer_seek ( struct interface *intf, off_t offset, int whence ) {
253
 	struct io_buffer *iobuf;
283
 	struct io_buffer *iobuf;
254
 	struct xfer_metadata meta = {
284
 	struct xfer_metadata meta = {
255
 		.offset = offset,
285
 		.offset = offset,
256
 		.whence = whence,
286
 		.whence = whence,
257
 	};
287
 	};
258
 
288
 
259
-	DBGC ( xfer, "XFER %p seek %s+%ld\n", xfer,
260
-	       whence_text ( whence ), offset );
289
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " seek %s+%ld\n",
290
+	       INTF_DBG ( intf ), whence_text ( whence ), offset );
261
 
291
 
262
 	/* Allocate and send a zero-length data buffer */
292
 	/* Allocate and send a zero-length data buffer */
263
-	iobuf = xfer_alloc_iob ( xfer, 0 );
293
+	iobuf = xfer_alloc_iob ( intf, 0 );
264
 	if ( ! iobuf )
294
 	if ( ! iobuf )
265
 		return -ENOMEM;
295
 		return -ENOMEM;
266
-	return xfer_deliver_iob_meta ( xfer, iobuf, &meta );
267
-}
268
-
269
-/****************************************************************************
270
- *
271
- * Helper methods
272
- *
273
- * These functions are designed to be used as methods in the
274
- * xfer_interface_operations table.
275
- *
276
- */
277
 
296
 
278
-/**
279
- * Ignore close() event
280
- *
281
- * @v xfer		Data transfer interface
282
- * @v rc		Reason for close
283
- */
284
-void ignore_xfer_close ( struct xfer_interface *xfer __unused,
285
-			 int rc __unused ) {
286
-	/* Nothing to do */
297
+	return xfer_deliver ( intf, iobuf, &meta );
287
 }
298
 }
288
-
289
-/**
290
- * Ignore vredirect() event
291
- *
292
- * @v xfer		Data transfer interface
293
- * @v type		New location type
294
- * @v args		Remaining arguments depend upon location type
295
- * @ret rc		Return status code
296
- */
297
-int ignore_xfer_vredirect ( struct xfer_interface *xfer __unused,
298
-			    int type __unused, va_list args __unused ) {
299
-	return 0;
300
-}
301
-
302
-/**
303
- * Unlimited flow control window
304
- *
305
- * @v xfer		Data transfer interface
306
- * @ret len		Length of window
307
- *
308
- * This handler indicates that the interface is always ready to accept
309
- * data.
310
- */
311
-size_t unlimited_xfer_window ( struct xfer_interface *xfer __unused ) {
312
-	return ~( ( size_t ) 0 );
313
-}
314
-
315
-/**
316
- * No flow control window
317
- *
318
- * @v xfer		Data transfer interface
319
- * @ret len		Length of window
320
- *
321
- * This handler indicates that the interface is never ready to accept
322
- * data.
323
- */
324
-size_t no_xfer_window ( struct xfer_interface *xfer __unused ) {
325
-	return 0;
326
-}
327
-
328
-/**
329
- * Allocate I/O buffer
330
- *
331
- * @v xfer		Data transfer interface
332
- * @v len		I/O buffer payload length
333
- * @ret iobuf		I/O buffer
334
- */
335
-struct io_buffer *
336
-default_xfer_alloc_iob ( struct xfer_interface *xfer __unused, size_t len ) {
337
-	return alloc_iob ( len );
338
-}
339
-
340
-/**
341
- * Deliver datagram as raw data
342
- *
343
- * @v xfer		Data transfer interface
344
- * @v iobuf		Datagram I/O buffer
345
- * @v meta		Data transfer metadata
346
- * @ret rc		Return status code
347
- *
348
- * This function is intended to be used as the deliver() method for
349
- * data transfer interfaces that prefer to handle raw data.
350
- */
351
-int xfer_deliver_as_raw ( struct xfer_interface *xfer,
352
-			  struct io_buffer *iobuf,
353
-			  struct xfer_metadata *meta __unused ) {
354
-	int rc;
355
-
356
-	rc = xfer->op->deliver_raw ( xfer, iobuf->data, iob_len ( iobuf ) );
357
-	free_iob ( iobuf );
358
-	return rc;
359
-}
360
-
361
-/**
362
- * Deliver datagram as I/O buffer
363
- *
364
- * @v xfer		Data transfer interface
365
- * @v data		Data buffer
366
- * @v len		Length of data buffer
367
- * @ret rc		Return status code
368
- *
369
- * This function is intended to be used as the deliver_raw() method
370
- * for data transfer interfaces that prefer to handle I/O buffers.
371
- */
372
-int xfer_deliver_as_iob ( struct xfer_interface *xfer,
373
-			  const void *data, size_t len ) {
374
-	struct io_buffer *iobuf;
375
-
376
-	iobuf = xfer->op->alloc_iob ( xfer, len );
377
-	if ( ! iobuf )
378
-		return -ENOMEM;
379
-
380
-	memcpy ( iob_put ( iobuf, len ), data, len );
381
-	return xfer->op->deliver_iob ( xfer, iobuf, &dummy_metadata );
382
-}
383
-
384
-/**
385
- * Ignore datagram as raw data event
386
- *
387
- * @v xfer		Data transfer interface
388
- * @v data		Data buffer
389
- * @v len		Length of data buffer
390
- * @ret rc		Return status code
391
- */
392
-int ignore_xfer_deliver_raw ( struct xfer_interface *xfer,
393
-			      const void *data __unused, size_t len ) {
394
-	DBGC ( xfer, "XFER %p %zd bytes delivered %s\n", xfer, len,
395
-	       ( ( xfer == &null_xfer ) ?
396
-		 "before connection" : "after termination" ) );
397
-	return 0;
398
-}
399
-
400
-/** Null data transfer interface operations */
401
-struct xfer_interface_operations null_xfer_ops = {
402
-	.close		= ignore_xfer_close,
403
-	.vredirect	= ignore_xfer_vredirect,
404
-	.window		= unlimited_xfer_window,
405
-	.alloc_iob	= default_xfer_alloc_iob,
406
-	.deliver_iob	= xfer_deliver_as_raw,
407
-	.deliver_raw	= ignore_xfer_deliver_raw,
408
-};
409
-
410
-/**
411
- * Null data transfer interface
412
- *
413
- * This is the interface to which data transfer interfaces are
414
- * connected when unplugged.  It will never generate messages, and
415
- * will silently absorb all received messages.
416
- */
417
-struct xfer_interface null_xfer = XFER_INIT ( &null_xfer_ops );

+ 14
- 32
src/drivers/block/srp.c View File

75
 static void srp_fail ( struct srp_device *srp, int rc ) {
75
 static void srp_fail ( struct srp_device *srp, int rc ) {
76
 
76
 
77
 	/* Close underlying socket */
77
 	/* Close underlying socket */
78
-	xfer_close ( &srp->socket, rc );
78
+	intf_restart ( &srp->socket, rc );
79
 
79
 
80
 	/* Clear session state */
80
 	/* Clear session state */
81
 	srp->state = 0;
81
 	srp->state = 0;
364
 /**
364
 /**
365
  * Receive data from underlying socket
365
  * Receive data from underlying socket
366
  *
366
  *
367
- * @v xfer		Data transfer interface
367
+ * @v srp		SRP device
368
  * @v iobuf		Datagram I/O buffer
368
  * @v iobuf		Datagram I/O buffer
369
  * @v meta		Data transfer metadata
369
  * @v meta		Data transfer metadata
370
  * @ret rc		Return status code
370
  * @ret rc		Return status code
371
  */
371
  */
372
-static int srp_xfer_deliver_iob ( struct xfer_interface *xfer,
373
-				  struct io_buffer *iobuf,
374
-				  struct xfer_metadata *meta __unused ) {
375
-	struct srp_device *srp =
376
-		container_of ( xfer, struct srp_device, socket );
372
+static int srp_xfer_deliver ( struct srp_device *srp,
373
+			      struct io_buffer *iobuf,
374
+			      struct xfer_metadata *meta __unused ) {
377
 	struct srp_common *common = iobuf->data;
375
 	struct srp_common *common = iobuf->data;
378
 	int ( * type ) ( struct srp_device *srp, struct io_buffer *iobuf );
376
 	int ( * type ) ( struct srp_device *srp, struct io_buffer *iobuf );
379
 	int rc;
377
 	int rc;
405
 	return rc;
403
 	return rc;
406
 }
404
 }
407
 
405
 
408
-/**
409
- * Underlying socket closed
410
- *
411
- * @v xfer		Data transfer interface
412
- * @v rc		Reason for close
413
- */
414
-static void srp_xfer_close ( struct xfer_interface *xfer, int rc ) {
415
-	struct srp_device *srp =
416
-		container_of ( xfer, struct srp_device, socket );
417
-
418
-	DBGC ( srp, "SRP %p socket closed: %s\n", srp, strerror ( rc ) );
419
-
420
-	srp_fail ( srp, rc );
421
-}
422
-
423
 /** SRP data transfer interface operations */
406
 /** SRP data transfer interface operations */
424
-static struct xfer_interface_operations srp_xfer_operations = {
425
-	.close		= srp_xfer_close,
426
-	.vredirect	= ignore_xfer_vredirect,
427
-	.window		= unlimited_xfer_window,
428
-	.alloc_iob	= default_xfer_alloc_iob,
429
-	.deliver_iob	= srp_xfer_deliver_iob,
430
-	.deliver_raw	= xfer_deliver_as_iob,
407
+static struct interface_operation srp_xfer_operations[] = {
408
+	INTF_OP ( xfer_deliver, struct srp_device *, srp_xfer_deliver ),
409
+	INTF_OP ( intf_close, struct srp_device *, srp_fail ),
431
 };
410
 };
432
 
411
 
412
+/** SRP data transfer interface descriptor */
413
+static struct interface_descriptor srp_xfer_desc =
414
+	INTF_DESC ( struct srp_device, socket, srp_xfer_operations );
415
+
433
 /**
416
 /**
434
  * Issue SCSI command via SRP
417
  * Issue SCSI command via SRP
435
  *
418
  *
483
 		goto err_alloc;
466
 		goto err_alloc;
484
 	}
467
 	}
485
 	ref_init ( &srp->refcnt, NULL );
468
 	ref_init ( &srp->refcnt, NULL );
486
-	xfer_init ( &srp->socket, &srp_xfer_operations, &srp->refcnt );
469
+	intf_init ( &srp->socket, &srp_xfer_desc, &srp->refcnt );
487
 	srp->transport = transport;
470
 	srp->transport = transport;
488
 	DBGC ( srp, "SRP %p using %s\n", srp, root_path );
471
 	DBGC ( srp, "SRP %p using %s\n", srp, root_path );
489
 
472
 
516
 		container_of ( scsi->backend, struct srp_device, refcnt );
499
 		container_of ( scsi->backend, struct srp_device, refcnt );
517
 
500
 
518
 	/* Close socket */
501
 	/* Close socket */
519
-	xfer_nullify ( &srp->socket );
520
-	xfer_close ( &srp->socket, 0 );
502
+	intf_shutdown ( &srp->socket, 0 );
521
 	scsi->command = scsi_detached_command;
503
 	scsi->command = scsi_detached_command;
522
 	ref_put ( scsi->backend );
504
 	ref_put ( scsi->backend );
523
 	scsi->backend = NULL;
505
 	scsi->backend = NULL;

+ 0
- 75
src/include/ipxe/filter.h View File

1
-#ifndef _IPXE_FILTER_H
2
-#define _IPXE_FILTER_H
3
-
4
-/** @file
5
- *
6
- * Data transfer filters
7
- *
8
- */
9
-
10
-FILE_LICENCE ( GPL2_OR_LATER );
11
-
12
-#include <stddef.h>
13
-#include <ipxe/xfer.h>
14
-
15
-/**
16
- * Half of a data transfer filter
17
- *
18
- * Embed two of these structures within a structure implementing a
19
- * data transfer filter, and intialise with filter_init().  You can
20
- * then use the filter_xxx() methods as the data transfer interface
21
- * methods as required.
22
- */
23
-struct xfer_filter_half {
24
-	/** Data transfer interface */
25
-	struct xfer_interface xfer;
26
-	/** Other half of the data transfer filter */
27
-	struct xfer_filter_half *other;
28
-};
29
-
30
-/**
31
- * Get data transfer interface for the other half of a data transfer filter
32
- *
33
- * @v xfer		Data transfer interface
34
- * @ret other		Other half's data transfer interface
35
- */
36
-static inline __attribute__ (( always_inline )) struct xfer_interface *
37
-filter_other_half ( struct xfer_interface *xfer ) {
38
-	struct xfer_filter_half *half = 
39
-		container_of ( xfer, struct xfer_filter_half, xfer );
40
-	return &half->other->xfer;
41
-}
42
-
43
-extern void filter_close ( struct xfer_interface *xfer, int rc );
44
-extern int filter_vredirect ( struct xfer_interface *xfer, int type,
45
-			      va_list args );
46
-extern size_t filter_window ( struct xfer_interface *xfer );
47
-extern struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
48
-					     size_t len );
49
-extern int filter_deliver_iob ( struct xfer_interface *xfer,
50
-				struct io_buffer *iobuf,
51
-				struct xfer_metadata *meta );
52
-extern int filter_deliver_raw ( struct xfer_interface *xfer, const void *data,
53
-				size_t len );
54
-
55
-/**
56
- * Initialise a data transfer filter
57
- *
58
- * @v left		"Left" half of the filter
59
- * @v left_op		Data transfer interface operations for "left" half
60
- * @v right		"Right" half of the filter
61
- * @v right_op		Data transfer interface operations for "right" half
62
- * @v refcnt		Containing object reference counter, or NULL
63
- */
64
-static inline void filter_init ( struct xfer_filter_half *left,
65
-				 struct xfer_interface_operations *left_op,
66
-				 struct xfer_filter_half *right,
67
-				 struct xfer_interface_operations *right_op,
68
-				 struct refcnt *refcnt ) {
69
-	xfer_init ( &left->xfer, left_op, refcnt );
70
-	xfer_init ( &right->xfer, right_op, refcnt );
71
-	left->other = right;
72
-	right->other = left;
73
-}
74
-
75
-#endif /* _IPXE_FILTER_H */

+ 3
- 3
src/include/ipxe/http.h View File

15
 /** HTTPS default port */
15
 /** HTTPS default port */
16
 #define HTTPS_PORT 443
16
 #define HTTPS_PORT 443
17
 
17
 
18
-extern int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
18
+extern int http_open_filter ( struct interface *xfer, struct uri *uri,
19
 			      unsigned int default_port,
19
 			      unsigned int default_port,
20
-			      int ( * filter ) ( struct xfer_interface *,
21
-						 struct xfer_interface ** ) );
20
+			      int ( * filter ) ( struct interface *,
21
+						 struct interface ** ) );
22
 
22
 
23
 #endif /* _IPXE_HTTP_H */
23
 #endif /* _IPXE_HTTP_H */

+ 1
- 1
src/include/ipxe/ib_cmrc.h View File

12
 #include <ipxe/infiniband.h>
12
 #include <ipxe/infiniband.h>
13
 #include <ipxe/xfer.h>
13
 #include <ipxe/xfer.h>
14
 
14
 
15
-extern int ib_cmrc_open ( struct xfer_interface *xfer,
15
+extern int ib_cmrc_open ( struct interface *xfer,
16
 			  struct ib_device *ibdev,
16
 			  struct ib_device *ibdev,
17
 			  struct ib_gid *dgid,
17
 			  struct ib_gid *dgid,
18
 			  struct ib_gid_half *service_id );
18
 			  struct ib_gid_half *service_id );

+ 1
- 1
src/include/ipxe/iscsi.h View File

498
 	struct refcnt refcnt;
498
 	struct refcnt refcnt;
499
 
499
 
500
 	/** Transport-layer socket */
500
 	/** Transport-layer socket */
501
-	struct xfer_interface socket;
501
+	struct interface socket;
502
 
502
 
503
 	/** Target address */
503
 	/** Target address */
504
 	char *target_address;
504
 	char *target_address;

+ 14
- 14
src/include/ipxe/open.h View File

13
 #include <ipxe/tables.h>
13
 #include <ipxe/tables.h>
14
 #include <ipxe/socket.h>
14
 #include <ipxe/socket.h>
15
 
15
 
16
-struct xfer_interface;
17
 struct uri;
16
 struct uri;
17
+struct interface;
18
 
18
 
19
 /** Location types */
19
 /** Location types */
20
 enum {
20
 enum {
53
 	const char *scheme;
53
 	const char *scheme;
54
 	/** Open URI
54
 	/** Open URI
55
 	 *
55
 	 *
56
-	 * @v xfer		Data transfer interface
56
+	 * @v intf		Object interface
57
 	 * @v uri		URI
57
 	 * @v uri		URI
58
 	 * @ret rc		Return status code
58
 	 * @ret rc		Return status code
59
 	 */
59
 	 */
60
-	int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
60
+	int ( * open ) ( struct interface *intf, struct uri *uri );
61
 };
61
 };
62
 
62
 
63
 /** URI opener table */
63
 /** URI opener table */
74
 	int family;
74
 	int family;
75
 	/** Open socket
75
 	/** Open socket
76
 	 *
76
 	 *
77
-	 * @v xfer		Data transfer interface
77
+	 * @v intf		Object interface
78
 	 * @v peer		Peer socket address
78
 	 * @v peer		Peer socket address
79
 	 * @v local		Local socket address, or NULL
79
 	 * @v local		Local socket address, or NULL
80
 	 * @ret rc		Return status code
80
 	 * @ret rc		Return status code
81
 	 */
81
 	 */
82
-	int ( * open ) ( struct xfer_interface *xfer, struct sockaddr *peer,
82
+	int ( * open ) ( struct interface *intf, struct sockaddr *peer,
83
 			 struct sockaddr *local );
83
 			 struct sockaddr *local );
84
 };
84
 };
85
 
85
 
89
 /** Register a socket opener */
89
 /** Register a socket opener */
90
 #define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
90
 #define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
91
 
91
 
92
-extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri );
93
-extern int xfer_open_uri_string ( struct xfer_interface *xfer,
92
+extern int xfer_open_uri ( struct interface *intf, struct uri *uri );
93
+extern int xfer_open_uri_string ( struct interface *intf,
94
 				  const char *uri_string );
94
 				  const char *uri_string );
95
-extern int xfer_open_named_socket ( struct xfer_interface *xfer,
96
-				    int semantics, struct sockaddr *peer,
97
-				    const char *name, struct sockaddr *local );
98
-extern int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
95
+extern int xfer_open_named_socket ( struct interface *intf, int semantics,
96
+				    struct sockaddr *peer, const char *name,
97
+				    struct sockaddr *local );
98
+extern int xfer_open_socket ( struct interface *intf, int semantics,
99
 			      struct sockaddr *peer, struct sockaddr *local );
99
 			      struct sockaddr *peer, struct sockaddr *local );
100
-extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
101
-extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
102
-extern int xfer_vreopen ( struct xfer_interface *xfer, int type,
100
+extern int xfer_vopen ( struct interface *intf, int type, va_list args );
101
+extern int xfer_open ( struct interface *intf, int type, ... );
102
+extern int xfer_vreopen ( struct interface *intf, int type,
103
 			  va_list args );
103
 			  va_list args );
104
 
104
 
105
 #endif /* _IPXE_OPEN_H */
105
 #endif /* _IPXE_OPEN_H */

+ 1
- 1
src/include/ipxe/srp.h View File

832
 	struct scsi_command *command;
832
 	struct scsi_command *command;
833
 
833
 
834
 	/** Underlying data transfer interface */
834
 	/** Underlying data transfer interface */
835
-	struct xfer_interface socket;
835
+	struct interface socket;
836
 
836
 
837
 	/** Transport type */
837
 	/** Transport type */
838
 	struct srp_transport_type *transport;
838
 	struct srp_transport_type *transport;

+ 5
- 5
src/include/ipxe/tls.h View File

11
 
11
 
12
 #include <stdint.h>
12
 #include <stdint.h>
13
 #include <ipxe/refcnt.h>
13
 #include <ipxe/refcnt.h>
14
-#include <ipxe/filter.h>
14
+#include <ipxe/interface.h>
15
 #include <ipxe/process.h>
15
 #include <ipxe/process.h>
16
 #include <ipxe/crypto.h>
16
 #include <ipxe/crypto.h>
17
 #include <ipxe/md5.h>
17
 #include <ipxe/md5.h>
134
 	struct refcnt refcnt;
134
 	struct refcnt refcnt;
135
 
135
 
136
 	/** Plaintext stream */
136
 	/** Plaintext stream */
137
-	struct xfer_filter_half plainstream;
137
+	struct interface plainstream;
138
 	/** Ciphertext stream */
138
 	/** Ciphertext stream */
139
-	struct xfer_filter_half cipherstream;
139
+	struct interface cipherstream;
140
 
140
 
141
 	/** Current TX cipher specification */
141
 	/** Current TX cipher specification */
142
 	struct tls_cipherspec tx_cipherspec;
142
 	struct tls_cipherspec tx_cipherspec;
181
 	void *rx_data;
181
 	void *rx_data;
182
 };
182
 };
183
 
183
 
184
-extern int add_tls ( struct xfer_interface *xfer,
185
-		     struct xfer_interface **next );
184
+extern int add_tls ( struct interface *xfer,
185
+		     struct interface **next );
186
 
186
 
187
 #endif /* _IPXE_TLS_H */
187
 #endif /* _IPXE_TLS_H */

+ 4
- 3
src/include/ipxe/udp.h View File

16
 #include <ipxe/tcpip.h>
16
 #include <ipxe/tcpip.h>
17
 #include <ipxe/if_ether.h>
17
 #include <ipxe/if_ether.h>
18
 
18
 
19
-struct xfer_interface;
19
+struct interface;
20
+struct sockaddr;
20
 
21
 
21
 /**
22
 /**
22
  * UDP constants
23
  * UDP constants
40
 	uint16_t chksum;
41
 	uint16_t chksum;
41
 };
42
 };
42
 
43
 
43
-extern int udp_open_promisc ( struct xfer_interface *xfer );
44
-extern int udp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
44
+extern int udp_open_promisc ( struct interface *xfer );
45
+extern int udp_open ( struct interface *xfer, struct sockaddr *peer,
45
 		      struct sockaddr *local );
46
 		      struct sockaddr *local );
46
 
47
 
47
 #endif /* _IPXE_UDP_H */
48
 #endif /* _IPXE_UDP_H */

+ 31
- 214
src/include/ipxe/xfer.h View File

12
 #include <stddef.h>
12
 #include <stddef.h>
13
 #include <stdarg.h>
13
 #include <stdarg.h>
14
 #include <ipxe/interface.h>
14
 #include <ipxe/interface.h>
15
-#include <ipxe/iobuf.h>
16
 
15
 
17
-struct xfer_interface;
18
 struct xfer_metadata;
16
 struct xfer_metadata;
19
-
20
-/** Data transfer interface operations */
21
-struct xfer_interface_operations {
22
-	/** Close interface
23
-	 *
24
-	 * @v xfer		Data transfer interface
25
-	 * @v rc		Reason for close
26
-	 */
27
-	void ( * close ) ( struct xfer_interface *xfer, int rc );
28
-	/** Redirect to new location
29
-	 *
30
-	 * @v xfer		Data transfer interface
31
-	 * @v type		New location type
32
-	 * @v args		Remaining arguments depend upon location type
33
-	 * @ret rc		Return status code
34
-	 */
35
-	int ( * vredirect ) ( struct xfer_interface *xfer, int type,
36
-			      va_list args );
37
-	/** Check flow control window
38
-	 *
39
-	 * @v xfer		Data transfer interface
40
-	 * @ret len		Length of window
41
-	 *
42
-	 * Flow control is regarded as advisory but not mandatory.
43
-	 * Users who have control over their own rate of data
44
-	 * generation should perform a flow control check before
45
-	 * generating new data.  Users who have no control (such as
46
-	 * NIC drivers or filter layers) are not obliged to check.
47
-	 *
48
-	 * Data transfer interfaces must be prepared to accept
49
-	 * datagrams even if they are advertising a window of zero
50
-	 * bytes.
51
-	 */
52
-	size_t ( * window ) ( struct xfer_interface *xfer );
53
-	/** Allocate I/O buffer
54
-	 *
55
-	 * @v xfer		Data transfer interface
56
-	 * @v len		I/O buffer payload length
57
-	 * @ret iobuf		I/O buffer
58
-	 */
59
-	struct io_buffer * ( * alloc_iob ) ( struct xfer_interface *xfer,
60
-					     size_t len );
61
-	/** Deliver datagram as I/O buffer with metadata
62
-	 *
63
-	 * @v xfer		Data transfer interface
64
-	 * @v iobuf		Datagram I/O buffer
65
-	 * @v meta		Data transfer metadata
66
-	 * @ret rc		Return status code
67
-	 *
68
-	 * A data transfer interface that wishes to support only raw
69
-	 * data delivery should set this method to
70
-	 * xfer_deliver_as_raw().
71
-	 */
72
-	int ( * deliver_iob ) ( struct xfer_interface *xfer,
73
-				struct io_buffer *iobuf,
74
-				struct xfer_metadata *meta );
75
-	/** Deliver datagram as raw data
76
-	 *
77
-	 * @v xfer		Data transfer interface
78
-	 * @v data		Data buffer
79
-	 * @v len		Length of data buffer
80
-	 * @ret rc		Return status code
81
-	 *
82
-	 * A data transfer interface that wishes to support only I/O
83
-	 * buffer delivery should set this method to
84
-	 * xfer_deliver_as_iob().
85
-	 */
86
-	int ( * deliver_raw ) ( struct xfer_interface *xfer,
87
-				const void *data, size_t len );
88
-};
89
-
90
-/** A data transfer interface */
91
-struct xfer_interface {
92
-	/** Generic object communication interface */
93
-	struct interface intf;
94
-	/** Operations for received messages */
95
-	struct xfer_interface_operations *op;
96
-};
17
+struct io_buffer;
18
+struct sockaddr;
19
+struct net_device;
97
 
20
 
98
 /** Basis positions for seek() events */
21
 /** Basis positions for seek() events */
99
 enum seek_whence {
22
 enum seek_whence {
132
 	}
55
 	}
133
 }
56
 }
134
 
57
 
135
-extern struct xfer_interface null_xfer;
136
-extern struct xfer_interface_operations null_xfer_ops;
58
+/* Data transfer interface operations */
137
 
59
 
138
-extern void xfer_close ( struct xfer_interface *xfer, int rc );
139
-extern int xfer_vredirect ( struct xfer_interface *xfer, int type,
60
+extern int xfer_vredirect ( struct interface *intf, int type,
140
 			    va_list args );
61
 			    va_list args );
141
-extern int xfer_redirect ( struct xfer_interface *xfer, int type, ... );
142
-extern size_t xfer_window ( struct xfer_interface *xfer );
143
-extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer,
144
-					   size_t len );
145
-extern int xfer_deliver_iob ( struct xfer_interface *xfer,
146
-			      struct io_buffer *iobuf );
147
-extern int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
148
-				   struct io_buffer *iobuf,
149
-				   struct xfer_metadata *meta );
150
-extern int xfer_deliver_raw ( struct xfer_interface *xfer,
151
-			      const void *data, size_t len );
152
-extern int xfer_vprintf ( struct xfer_interface *xfer,
153
-			  const char *format, va_list args );
154
-extern int __attribute__ (( format ( printf, 2, 3 ) ))
155
-xfer_printf ( struct xfer_interface *xfer, const char *format, ... );
156
-extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence );
157
-
158
-extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
159
-extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,
160
-				   int type, va_list args );
161
-extern size_t unlimited_xfer_window ( struct xfer_interface *xfer );
162
-extern size_t no_xfer_window ( struct xfer_interface *xfer );
163
-extern struct io_buffer * default_xfer_alloc_iob ( struct xfer_interface *xfer,
164
-						   size_t len );
165
-extern int xfer_deliver_as_raw ( struct xfer_interface *xfer,
166
-				 struct io_buffer *iobuf,
167
-				 struct xfer_metadata *meta );
168
-extern int xfer_deliver_as_iob ( struct xfer_interface *xfer,
169
-				 const void *data, size_t len );
170
-extern int ignore_xfer_deliver_raw ( struct xfer_interface *xfer,
171
-				     const void *data __unused, size_t len );
172
-
173
-/**
174
- * Initialise a data transfer interface
175
- *
176
- * @v xfer		Data transfer interface
177
- * @v op		Data transfer interface operations
178
- * @v refcnt		Containing object reference counter, or NULL
179
- */
180
-static inline void xfer_init ( struct xfer_interface *xfer,
181
-			       struct xfer_interface_operations *op,
182
-			       struct refcnt *refcnt ) {
183
-	xfer->intf.dest = &null_xfer.intf;
184
-	xfer->intf.refcnt = refcnt;
185
-	xfer->op = op;
186
-}
187
-
188
-/**
189
- * Initialise a static data transfer interface
190
- *
191
- * @v operations		Data transfer interface operations
192
- */
193
-#define XFER_INIT( operations ) {			\
194
-		.intf = {				\
195
-			.dest = &null_xfer.intf,	\
196
-			.refcnt = NULL,			\
197
-		},					\
198
-		.op = operations,			\
199
-	}
62
+#define xfer_vredirect_TYPE( object_type ) \
63
+	typeof ( int ( object_type, int type, va_list args ) )
200
 
64
 
201
-/**
202
- * Get data transfer interface from generic object communication interface
203
- *
204
- * @v intf		Generic object communication interface
205
- * @ret xfer		Data transfer interface
206
- */
207
-static inline __attribute__ (( always_inline )) struct xfer_interface *
208
-intf_to_xfer ( struct interface *intf ) {
209
-	return container_of ( intf, struct xfer_interface, intf );
210
-}
211
-
212
-/**
213
- * Get reference to destination data transfer interface
214
- *
215
- * @v xfer		Data transfer interface
216
- * @ret dest		Destination interface
217
- */
218
-static inline __attribute__ (( always_inline )) struct xfer_interface *
219
-xfer_get_dest ( struct xfer_interface *xfer ) {
220
-	return intf_to_xfer ( intf_get ( xfer->intf.dest ) );
221
-}
65
+extern size_t xfer_window ( struct interface *intf );
66
+#define xfer_window_TYPE( object_type ) \
67
+	typeof ( size_t ( object_type ) )
222
 
68
 
223
-/**
224
- * Drop reference to data transfer interface
225
- *
226
- * @v xfer		Data transfer interface
227
- */
228
-static inline __attribute__ (( always_inline )) void
229
-xfer_put ( struct xfer_interface *xfer ) {
230
-	intf_put ( &xfer->intf );
231
-}
232
-
233
-/**
234
- * Plug a data transfer interface into a new destination interface
235
- *
236
- * @v xfer		Data transfer interface
237
- * @v dest		New destination interface
238
- */
239
-static inline __attribute__ (( always_inline )) void
240
-xfer_plug ( struct xfer_interface *xfer, struct xfer_interface *dest ) {
241
-	intf_plug ( &xfer->intf, &dest->intf );
242
-}
69
+extern struct io_buffer * xfer_alloc_iob ( struct interface *intf,
70
+					   size_t len );
71
+#define xfer_alloc_iob_TYPE( object_type ) \
72
+	typeof ( struct io_buffer * ( object_type, size_t len ) )
243
 
73
 
244
-/**
245
- * Plug two data transfer interfaces together
246
- *
247
- * @v a			Data transfer interface A
248
- * @v b			Data transfer interface B
249
- */
250
-static inline __attribute__ (( always_inline )) void
251
-xfer_plug_plug ( struct xfer_interface *a, struct xfer_interface *b ) {
252
-	intf_plug_plug ( &a->intf, &b->intf );
253
-}
74
+extern int xfer_deliver ( struct interface *intf,
75
+			  struct io_buffer *iobuf,
76
+			  struct xfer_metadata *meta );
77
+#define xfer_deliver_TYPE( object_type )			\
78
+	typeof ( int ( object_type, struct io_buffer *iobuf,	\
79
+		       struct xfer_metadata *meta ) )
254
 
80
 
255
-/**
256
- * Unplug a data transfer interface
257
- *
258
- * @v xfer		Data transfer interface
259
- */
260
-static inline __attribute__ (( always_inline )) void
261
-xfer_unplug ( struct xfer_interface *xfer ) {
262
-	intf_plug ( &xfer->intf, &null_xfer.intf );
263
-}
81
+/* Data transfer interface helper functions */
264
 
82
 
265
-/**
266
- * Stop using a data transfer interface
267
- *
268
- * @v xfer		Data transfer interface
269
- *
270
- * After calling this method, no further messages will be received via
271
- * the interface.
272
- */
273
-static inline void xfer_nullify ( struct xfer_interface *xfer ) {
274
-	xfer->op = &null_xfer_ops;
275
-};
83
+extern int xfer_redirect ( struct interface *xfer, int type, ... );
84
+extern int xfer_deliver_iob ( struct interface *intf,
85
+			      struct io_buffer *iobuf );
86
+extern int xfer_deliver_raw ( struct interface *intf,
87
+			      const void *data, size_t len );
88
+extern int xfer_vprintf ( struct interface *intf,
89
+			  const char *format, va_list args );
90
+extern int __attribute__ (( format ( printf, 2, 3 ) ))
91
+xfer_printf ( struct interface *intf, const char *format, ... );
92
+extern int xfer_seek ( struct interface *intf, off_t offset, int whence );
276
 
93
 
277
 #endif /* _IPXE_XFER_H */
94
 #endif /* _IPXE_XFER_H */

+ 21
- 37
src/net/infiniband/ib_cmrc.c View File

70
 	/** Reference count */
70
 	/** Reference count */
71
 	struct refcnt refcnt;
71
 	struct refcnt refcnt;
72
 	/** Data transfer interface */
72
 	/** Data transfer interface */
73
-	struct xfer_interface xfer;
73
+	struct interface xfer;
74
 	/** Infiniband device */
74
 	/** Infiniband device */
75
 	struct ib_device *ibdev;
75
 	struct ib_device *ibdev;
76
 	/** Completion queue */
76
 	/** Completion queue */
135
 static void ib_cmrc_close ( struct ib_cmrc_connection *cmrc, int rc ) {
135
 static void ib_cmrc_close ( struct ib_cmrc_connection *cmrc, int rc ) {
136
 
136
 
137
 	/* Close data transfer interface */
137
 	/* Close data transfer interface */
138
-	xfer_nullify ( &cmrc->xfer );
139
-	xfer_close ( &cmrc->xfer, rc );
138
+	intf_shutdown ( &cmrc->xfer, rc );
140
 
139
 
141
 	/* Schedule shutdown process */
140
 	/* Schedule shutdown process */
142
 	process_add ( &cmrc->shutdown );
141
 	process_add ( &cmrc->shutdown );
263
 /**
262
 /**
264
  * Send data via CMRC
263
  * Send data via CMRC
265
  *
264
  *
266
- * @v xfer		Data transfer interface
265
+ * @v cmrc		CMRC connection
267
  * @v iobuf		Datagram I/O buffer
266
  * @v iobuf		Datagram I/O buffer
268
  * @v meta		Data transfer metadata
267
  * @v meta		Data transfer metadata
269
  * @ret rc		Return status code
268
  * @ret rc		Return status code
270
  */
269
  */
271
-static int ib_cmrc_xfer_deliver_iob ( struct xfer_interface *xfer,
272
-				      struct io_buffer *iobuf,
273
-				      struct xfer_metadata *meta __unused ) {
274
-	struct ib_cmrc_connection *cmrc =
275
-		container_of ( xfer, struct ib_cmrc_connection, xfer );
270
+static int ib_cmrc_xfer_deliver ( struct ib_cmrc_connection *cmrc,
271
+				  struct io_buffer *iobuf,
272
+				  struct xfer_metadata *meta __unused ) {
276
 	int rc;
273
 	int rc;
277
 
274
 
278
 	/* If no connection has yet been attempted, send this datagram
275
 	/* If no connection has yet been attempted, send this datagram
326
 /**
323
 /**
327
  * Check CMRC flow control window
324
  * Check CMRC flow control window
328
  *
325
  *
329
- * @v xfer		Data transfer interface
326
+ * @v cmrc		CMRC connection
330
  * @ret len		Length of window
327
  * @ret len		Length of window
331
  */
328
  */
332
-static size_t ib_cmrc_xfer_window ( struct xfer_interface *xfer ) {
333
-	struct ib_cmrc_connection *cmrc =
334
-		container_of ( xfer, struct ib_cmrc_connection, xfer );
329
+static size_t ib_cmrc_xfer_window ( struct ib_cmrc_connection *cmrc ) {
335
 
330
 
336
 	/* We indicate a window only when we are successfully
331
 	/* We indicate a window only when we are successfully
337
 	 * connected.
332
 	 * connected.
339
 	return ( cmrc->connected ? IB_MAX_PAYLOAD_SIZE : 0 );
334
 	return ( cmrc->connected ? IB_MAX_PAYLOAD_SIZE : 0 );
340
 }
335
 }
341
 
336
 
342
-/**
343
- * Close CMRC data-transfer interface
344
- *
345
- * @v xfer		Data transfer interface
346
- * @v rc		Reason for close
347
- */
348
-static void ib_cmrc_xfer_close ( struct xfer_interface *xfer, int rc ) {
349
-	struct ib_cmrc_connection *cmrc =
350
-		container_of ( xfer, struct ib_cmrc_connection, xfer );
351
-
352
-	DBGC ( cmrc, "CMRC %p closed: %s\n", cmrc, strerror ( rc ) );
353
-	ib_cmrc_close ( cmrc, rc );
354
-}
355
-
356
 /** CMRC data transfer interface operations */
337
 /** CMRC data transfer interface operations */
357
-static struct xfer_interface_operations ib_cmrc_xfer_operations = {
358
-	.close		= ib_cmrc_xfer_close,
359
-	.vredirect	= ignore_xfer_vredirect,
360
-	.window		= ib_cmrc_xfer_window,
361
-	.alloc_iob	= default_xfer_alloc_iob,
362
-	.deliver_iob	= ib_cmrc_xfer_deliver_iob,
363
-	.deliver_raw	= xfer_deliver_as_iob,
338
+static struct interface_operation ib_cmrc_xfer_operations[] = {
339
+	INTF_OP ( xfer_deliver, struct ib_cmrc_connection *,
340
+		  ib_cmrc_xfer_deliver ),
341
+	INTF_OP ( xfer_window, struct ib_cmrc_connection *,
342
+		  ib_cmrc_xfer_window ),
343
+	INTF_OP ( intf_close, struct ib_cmrc_connection *, ib_cmrc_close ),
364
 };
344
 };
365
 
345
 
346
+/** CMRC data transfer interface descriptor */
347
+static struct interface_descriptor ib_cmrc_xfer_desc =
348
+	INTF_DESC ( struct ib_cmrc_connection, xfer, ib_cmrc_xfer_operations );
349
+
366
 /**
350
 /**
367
  * Open CMRC connection
351
  * Open CMRC connection
368
  *
352
  *
372
  * @v service_id	Service ID
356
  * @v service_id	Service ID
373
  * @ret rc		Returns status code
357
  * @ret rc		Returns status code
374
  */
358
  */
375
-int ib_cmrc_open ( struct xfer_interface *xfer, struct ib_device *ibdev,
359
+int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev,
376
 		   struct ib_gid *dgid, struct ib_gid_half *service_id ) {
360
 		   struct ib_gid *dgid, struct ib_gid_half *service_id ) {
377
 	struct ib_cmrc_connection *cmrc;
361
 	struct ib_cmrc_connection *cmrc;
378
 	int rc;
362
 	int rc;
384
 		goto err_alloc;
368
 		goto err_alloc;
385
 	}
369
 	}
386
 	ref_init ( &cmrc->refcnt, NULL );
370
 	ref_init ( &cmrc->refcnt, NULL );
387
-	xfer_init ( &cmrc->xfer, &ib_cmrc_xfer_operations, &cmrc->refcnt );
371
+	intf_init ( &cmrc->xfer, &ib_cmrc_xfer_desc, &cmrc->refcnt );
388
 	cmrc->ibdev = ibdev;
372
 	cmrc->ibdev = ibdev;
389
 	memcpy ( &cmrc->dgid, dgid, sizeof ( cmrc->dgid ) );
373
 	memcpy ( &cmrc->dgid, dgid, sizeof ( cmrc->dgid ) );
390
 	memcpy ( &cmrc->service_id, service_id, sizeof ( cmrc->service_id ) );
374
 	memcpy ( &cmrc->service_id, service_id, sizeof ( cmrc->service_id ) );
422
 	/* Attach to parent interface, transfer reference (implicitly)
406
 	/* Attach to parent interface, transfer reference (implicitly)
423
 	 * to our shutdown process, and return.
407
 	 * to our shutdown process, and return.
424
 	 */
408
 	 */
425
-	xfer_plug_plug ( &cmrc->xfer, xfer );
409
+	intf_plug_plug ( &cmrc->xfer, xfer );
426
 	return 0;
410
 	return 0;
427
 
411
 
428
 	ib_destroy_qp ( ibdev, cmrc->qp );
412
 	ib_destroy_qp ( ibdev, cmrc->qp );

+ 23
- 29
src/net/tcp.c View File

31
 	struct list_head list;
31
 	struct list_head list;
32
 
32
 
33
 	/** Data transfer interface */
33
 	/** Data transfer interface */
34
-	struct xfer_interface xfer;
34
+	struct interface xfer;
35
 	/** Data transfer interface closed flag */
35
 	/** Data transfer interface closed flag */
36
 	int xfer_closed;
36
 	int xfer_closed;
37
 
37
 
92
 static LIST_HEAD ( tcp_conns );
92
 static LIST_HEAD ( tcp_conns );
93
 
93
 
94
 /* Forward declarations */
94
 /* Forward declarations */
95
-static struct xfer_interface_operations tcp_xfer_operations;
95
+static struct interface_descriptor tcp_xfer_desc;
96
 static void tcp_expired ( struct retry_timer *timer, int over );
96
 static void tcp_expired ( struct retry_timer *timer, int over );
97
 static int tcp_rx_ack ( struct tcp_connection *tcp, uint32_t ack,
97
 static int tcp_rx_ack ( struct tcp_connection *tcp, uint32_t ack,
98
 			uint32_t win );
98
 			uint32_t win );
211
  * @v local		Local socket address, or NULL
211
  * @v local		Local socket address, or NULL
212
  * @ret rc		Return status code
212
  * @ret rc		Return status code
213
  */
213
  */
214
-static int tcp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
214
+static int tcp_open ( struct interface *xfer, struct sockaddr *peer,
215
 		      struct sockaddr *local ) {
215
 		      struct sockaddr *local ) {
216
 	struct sockaddr_tcpip *st_peer = ( struct sockaddr_tcpip * ) peer;
216
 	struct sockaddr_tcpip *st_peer = ( struct sockaddr_tcpip * ) peer;
217
 	struct sockaddr_tcpip *st_local = ( struct sockaddr_tcpip * ) local;
217
 	struct sockaddr_tcpip *st_local = ( struct sockaddr_tcpip * ) local;
225
 		return -ENOMEM;
225
 		return -ENOMEM;
226
 	DBGC ( tcp, "TCP %p allocated\n", tcp );
226
 	DBGC ( tcp, "TCP %p allocated\n", tcp );
227
 	ref_init ( &tcp->refcnt, NULL );
227
 	ref_init ( &tcp->refcnt, NULL );
228
-	xfer_init ( &tcp->xfer, &tcp_xfer_operations, &tcp->refcnt );
228
+	intf_init ( &tcp->xfer, &tcp_xfer_desc, &tcp->refcnt );
229
 	timer_init ( &tcp->timer, tcp_expired );
229
 	timer_init ( &tcp->timer, tcp_expired );
230
 	tcp->prev_tcp_state = TCP_CLOSED;
230
 	tcp->prev_tcp_state = TCP_CLOSED;
231
 	tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN );
231
 	tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN );
245
 	/* Attach parent interface, transfer reference to connection
245
 	/* Attach parent interface, transfer reference to connection
246
 	 * list and return
246
 	 * list and return
247
 	 */
247
 	 */
248
-	xfer_plug_plug ( &tcp->xfer, xfer );
248
+	intf_plug_plug ( &tcp->xfer, xfer );
249
 	list_add ( &tcp->list, &tcp_conns );
249
 	list_add ( &tcp->list, &tcp_conns );
250
 	return 0;
250
 	return 0;
251
 
251
 
268
 	struct io_buffer *tmp;
268
 	struct io_buffer *tmp;
269
 
269
 
270
 	/* Close data transfer interface */
270
 	/* Close data transfer interface */
271
-	xfer_nullify ( &tcp->xfer );
272
-	xfer_close ( &tcp->xfer, rc );
271
+	intf_shutdown ( &tcp->xfer, rc );
273
 	tcp->xfer_closed = 1;
272
 	tcp->xfer_closed = 1;
274
 
273
 
275
 	/* If we are in CLOSED, or have otherwise not yet received a
274
 	/* If we are in CLOSED, or have otherwise not yet received a
1044
 /**
1043
 /**
1045
  * Close interface
1044
  * Close interface
1046
  *
1045
  *
1047
- * @v xfer		Data transfer interface
1046
+ * @v tcp		TCP connection
1048
  * @v rc		Reason for close
1047
  * @v rc		Reason for close
1049
  */
1048
  */
1050
-static void tcp_xfer_close ( struct xfer_interface *xfer, int rc ) {
1051
-	struct tcp_connection *tcp =
1052
-		container_of ( xfer, struct tcp_connection, xfer );
1049
+static void tcp_xfer_close ( struct tcp_connection *tcp, int rc ) {
1053
 
1050
 
1054
 	/* Close data transfer interface */
1051
 	/* Close data transfer interface */
1055
 	tcp_close ( tcp, rc );
1052
 	tcp_close ( tcp, rc );
1061
 /**
1058
 /**
1062
  * Check flow control window
1059
  * Check flow control window
1063
  *
1060
  *
1064
- * @v xfer		Data transfer interface
1061
+ * @v tcp		TCP connection
1065
  * @ret len		Length of window
1062
  * @ret len		Length of window
1066
  */
1063
  */
1067
-static size_t tcp_xfer_window ( struct xfer_interface *xfer ) {
1068
-	struct tcp_connection *tcp =
1069
-		container_of ( xfer, struct tcp_connection, xfer );
1064
+static size_t tcp_xfer_window ( struct tcp_connection *tcp ) {
1070
 
1065
 
1071
 	/* Not ready if data queue is non-empty.  This imposes a limit
1066
 	/* Not ready if data queue is non-empty.  This imposes a limit
1072
 	 * of only one unACKed packet in the TX queue at any time; we
1067
 	 * of only one unACKed packet in the TX queue at any time; we
1082
 /**
1077
 /**
1083
  * Deliver datagram as I/O buffer
1078
  * Deliver datagram as I/O buffer
1084
  *
1079
  *
1085
- * @v xfer		Data transfer interface
1080
+ * @v tcp		TCP connection
1086
  * @v iobuf		Datagram I/O buffer
1081
  * @v iobuf		Datagram I/O buffer
1087
  * @v meta		Data transfer metadata
1082
  * @v meta		Data transfer metadata
1088
  * @ret rc		Return status code
1083
  * @ret rc		Return status code
1089
  */
1084
  */
1090
-static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
1091
-				  struct io_buffer *iobuf,
1092
-				  struct xfer_metadata *meta __unused ) {
1093
-	struct tcp_connection *tcp =
1094
-		container_of ( xfer, struct tcp_connection, xfer );
1085
+static int tcp_xfer_deliver ( struct tcp_connection *tcp,
1086
+			      struct io_buffer *iobuf,
1087
+			      struct xfer_metadata *meta __unused ) {
1095
 
1088
 
1096
 	/* Enqueue packet */
1089
 	/* Enqueue packet */
1097
 	list_add_tail ( &iobuf->list, &tcp->queue );
1090
 	list_add_tail ( &iobuf->list, &tcp->queue );
1103
 }
1096
 }
1104
 
1097
 
1105
 /** TCP data transfer interface operations */
1098
 /** TCP data transfer interface operations */
1106
-static struct xfer_interface_operations tcp_xfer_operations = {
1107
-	.close		= tcp_xfer_close,
1108
-	.vredirect	= ignore_xfer_vredirect,
1109
-	.window		= tcp_xfer_window,
1110
-	.alloc_iob	= default_xfer_alloc_iob,
1111
-	.deliver_iob	= tcp_xfer_deliver_iob,
1112
-	.deliver_raw	= xfer_deliver_as_iob,
1099
+static struct interface_operation tcp_xfer_operations[] = {
1100
+	INTF_OP ( xfer_deliver, struct tcp_connection *, tcp_xfer_deliver ),
1101
+	INTF_OP ( xfer_window, struct tcp_connection *, tcp_xfer_window ),
1102
+	INTF_OP ( intf_close, struct tcp_connection *, tcp_xfer_close ),
1113
 };
1103
 };
1114
 
1104
 
1105
+/** TCP data transfer interface descriptor */
1106
+static struct interface_descriptor tcp_xfer_desc =
1107
+	INTF_DESC ( struct tcp_connection, xfer, tcp_xfer_operations );
1108
+
1115
 /***************************************************************************
1109
 /***************************************************************************
1116
  *
1110
  *
1117
  * Openers
1111
  * Openers
1136
  * @v uri		URI
1130
  * @v uri		URI
1137
  * @ret rc		Return status code
1131
  * @ret rc		Return status code
1138
  */
1132
  */
1139
-static int tcp_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
1133
+static int tcp_open_uri ( struct interface *xfer, struct uri *uri ) {
1140
 	struct sockaddr_tcpip peer;
1134
 	struct sockaddr_tcpip peer;
1141
 
1135
 
1142
 	/* Sanity check */
1136
 	/* Sanity check */

+ 53
- 91
src/net/tcp/ftp.c View File

8
 #include <ipxe/socket.h>
8
 #include <ipxe/socket.h>
9
 #include <ipxe/tcpip.h>
9
 #include <ipxe/tcpip.h>
10
 #include <ipxe/in.h>
10
 #include <ipxe/in.h>
11
+#include <ipxe/iobuf.h>
11
 #include <ipxe/xfer.h>
12
 #include <ipxe/xfer.h>
12
 #include <ipxe/open.h>
13
 #include <ipxe/open.h>
13
 #include <ipxe/uri.h>
14
 #include <ipxe/uri.h>
48
 	/** Reference counter */
49
 	/** Reference counter */
49
 	struct refcnt refcnt;
50
 	struct refcnt refcnt;
50
 	/** Data transfer interface */
51
 	/** Data transfer interface */
51
-	struct xfer_interface xfer;
52
+	struct interface xfer;
52
 
53
 
53
 	/** URI being fetched */
54
 	/** URI being fetched */
54
 	struct uri *uri;
55
 	struct uri *uri;
55
 	/** FTP control channel interface */
56
 	/** FTP control channel interface */
56
-	struct xfer_interface control;
57
+	struct interface control;
57
 	/** FTP data channel interface */
58
 	/** FTP data channel interface */
58
-	struct xfer_interface data;
59
+	struct interface data;
59
 
60
 
60
 	/** Current state */
61
 	/** Current state */
61
 	enum ftp_state state;
62
 	enum ftp_state state;
95
 	DBGC ( ftp, "FTP %p completed (%s)\n", ftp, strerror ( rc ) );
96
 	DBGC ( ftp, "FTP %p completed (%s)\n", ftp, strerror ( rc ) );
96
 
97
 
97
 	/* Close all data transfer interfaces */
98
 	/* Close all data transfer interfaces */
98
-	xfer_nullify ( &ftp->xfer );
99
-	xfer_close ( &ftp->xfer, rc );
100
-	xfer_nullify ( &ftp->control );
101
-	xfer_close ( &ftp->control, rc );
102
-	xfer_nullify ( &ftp->data );
103
-	xfer_close ( &ftp->data, rc );
99
+	intf_shutdown ( &ftp->data, rc );
100
+	intf_shutdown ( &ftp->control, rc );
101
+	intf_shutdown ( &ftp->xfer, rc );
104
 }
102
 }
105
 
103
 
106
 /*****************************************************************************
104
 /*****************************************************************************
166
 	[FTP_DONE]	= { NULL, NULL },
164
 	[FTP_DONE]	= { NULL, NULL },
167
 };
165
 };
168
 
166
 
169
-/**
170
- * Handle control channel being closed
171
- *
172
- * @v control		FTP control channel interface
173
- * @v rc		Reason for close
174
- *
175
- * When the control channel is closed, the data channel must also be
176
- * closed, if it is currently open.
177
- */
178
-static void ftp_control_close ( struct xfer_interface *control, int rc ) {
179
-	struct ftp_request *ftp =
180
-		container_of ( control, struct ftp_request, control );
181
-
182
-	DBGC ( ftp, "FTP %p control connection closed: %s\n",
183
-	       ftp, strerror ( rc ) );
184
-
185
-	/* Complete FTP operation */
186
-	ftp_done ( ftp, rc );
187
-}
188
-
189
 /**
167
 /**
190
  * Parse FTP byte sequence value
168
  * Parse FTP byte sequence value
191
  *
169
  *
298
 /**
276
 /**
299
  * Handle new data arriving on FTP control channel
277
  * Handle new data arriving on FTP control channel
300
  *
278
  *
301
- * @v control		FTP control channel interface
302
- * @v data		New data
303
- * @v len		Length of new data
279
+ * @v ftp		FTP request
280
+ * @v iob		I/O buffer
281
+ * @v meta		Data transfer metadata
282
+ * @ret rc		Return status code
304
  *
283
  *
305
  * Data is collected until a complete line is received, at which point
284
  * Data is collected until a complete line is received, at which point
306
  * its information is passed to ftp_reply().
285
  * its information is passed to ftp_reply().
307
  */
286
  */
308
-static int ftp_control_deliver_raw ( struct xfer_interface *control,
309
-				     const void *data, size_t len ) {
310
-	struct ftp_request *ftp =
311
-		container_of ( control, struct ftp_request, control );
287
+static int ftp_control_deliver ( struct ftp_request *ftp,
288
+				 struct io_buffer *iobuf,
289
+				 struct xfer_metadata *meta __unused ) {
290
+	char *data = iobuf->data;
291
+	size_t len = iob_len ( iobuf );
312
 	char *recvbuf = ftp->recvbuf;
292
 	char *recvbuf = ftp->recvbuf;
313
 	size_t recvsize = ftp->recvsize;
293
 	size_t recvsize = ftp->recvsize;
314
 	char c;
294
 	char c;
315
 	
295
 	
316
 	while ( len-- ) {
296
 	while ( len-- ) {
317
-		c = * ( ( char * ) data++ );
297
+		c = *(data++);
318
 		switch ( c ) {
298
 		switch ( c ) {
319
 		case '\r' :
299
 		case '\r' :
320
 		case '\n' :
300
 		case '\n' :
351
 	ftp->recvbuf = recvbuf;
331
 	ftp->recvbuf = recvbuf;
352
 	ftp->recvsize = recvsize;
332
 	ftp->recvsize = recvsize;
353
 
333
 
334
+	/* Free I/O buffer */
335
+	free_iob ( iobuf );
336
+
354
 	return 0;
337
 	return 0;
355
 }
338
 }
356
 
339
 
357
-/** FTP control channel operations */
358
-static struct xfer_interface_operations ftp_control_operations = {
359
-	.close		= ftp_control_close,
360
-	.vredirect	= xfer_vreopen,
361
-	.window		= unlimited_xfer_window,
362
-	.alloc_iob	= default_xfer_alloc_iob,
363
-	.deliver_iob	= xfer_deliver_as_raw,
364
-	.deliver_raw	= ftp_control_deliver_raw,
340
+/** FTP control channel interface operations */
341
+static struct interface_operation ftp_control_operations[] = {
342
+	INTF_OP ( xfer_deliver, struct ftp_request *, ftp_control_deliver ),
343
+	INTF_OP ( intf_close, struct ftp_request *, ftp_done ),
365
 };
344
 };
366
 
345
 
346
+/** FTP control channel interface descriptor */
347
+static struct interface_descriptor ftp_control_desc =
348
+	INTF_DESC ( struct ftp_request, control, ftp_control_operations );
349
+
367
 /*****************************************************************************
350
 /*****************************************************************************
368
  *
351
  *
369
  * FTP data channel
352
  * FTP data channel
373
 /**
356
 /**
374
  * Handle FTP data channel being closed
357
  * Handle FTP data channel being closed
375
  *
358
  *
376
- * @v data		FTP data channel interface
359
+ * @v ftp		FTP request
377
  * @v rc		Reason for closure
360
  * @v rc		Reason for closure
378
  *
361
  *
379
  * When the data channel is closed, the control channel should be left
362
  * When the data channel is closed, the control channel should be left
382
  *
365
  *
383
  * If the data channel is closed due to an error, we abort the request.
366
  * If the data channel is closed due to an error, we abort the request.
384
  */
367
  */
385
-static void ftp_data_closed ( struct xfer_interface *data, int rc ) {
386
-	struct ftp_request *ftp =
387
-		container_of ( data, struct ftp_request, data );
368
+static void ftp_data_closed ( struct ftp_request *ftp, int rc ) {
388
 
369
 
389
 	DBGC ( ftp, "FTP %p data connection closed: %s\n",
370
 	DBGC ( ftp, "FTP %p data connection closed: %s\n",
390
 	       ftp, strerror ( rc ) );
371
 	       ftp, strerror ( rc ) );
400
 /**
381
 /**
401
  * Handle data delivery via FTP data channel
382
  * Handle data delivery via FTP data channel
402
  *
383
  *
403
- * @v xfer		FTP data channel interface
384
+ * @v ftp		FTP request
404
  * @v iobuf		I/O buffer
385
  * @v iobuf		I/O buffer
405
  * @v meta		Data transfer metadata
386
  * @v meta		Data transfer metadata
406
  * @ret rc		Return status code
387
  * @ret rc		Return status code
407
  */
388
  */
408
-static int ftp_data_deliver_iob ( struct xfer_interface *data,
409
-				  struct io_buffer *iobuf,
410
-				  struct xfer_metadata *meta __unused ) {
411
-	struct ftp_request *ftp =
412
-		container_of ( data, struct ftp_request, data );
389
+static int ftp_data_deliver ( struct ftp_request *ftp,
390
+			      struct io_buffer *iobuf,
391
+			      struct xfer_metadata *meta __unused ) {
413
 	int rc;
392
 	int rc;
414
 
393
 
415
 	if ( ( rc = xfer_deliver_iob ( &ftp->xfer, iobuf ) ) != 0 ) {
394
 	if ( ( rc = xfer_deliver_iob ( &ftp->xfer, iobuf ) ) != 0 ) {
421
 	return 0;
400
 	return 0;
422
 }
401
 }
423
 
402
 
424
-/** FTP data channel operations */
425
-static struct xfer_interface_operations ftp_data_operations = {
426
-	.close		= ftp_data_closed,
427
-	.vredirect	= xfer_vreopen,
428
-	.window		= unlimited_xfer_window,
429
-	.alloc_iob	= default_xfer_alloc_iob,
430
-	.deliver_iob	= ftp_data_deliver_iob,
431
-	.deliver_raw	= xfer_deliver_as_iob,
403
+/** FTP data channel interface operations */
404
+static struct interface_operation ftp_data_operations[] = {
405
+	INTF_OP ( xfer_deliver, struct ftp_request *, ftp_data_deliver ),
406
+	INTF_OP ( intf_close, struct ftp_request *, ftp_data_closed ),
432
 };
407
 };
433
 
408
 
409
+/** FTP data channel interface descriptor */
410
+static struct interface_descriptor ftp_data_desc =
411
+	INTF_DESC ( struct ftp_request, data, ftp_data_operations );
412
+
434
 /*****************************************************************************
413
 /*****************************************************************************
435
  *
414
  *
436
  * Data transfer interface
415
  * Data transfer interface
437
  *
416
  *
438
  */
417
  */
439
 
418
 
440
-/**
441
- * Close FTP data transfer interface
442
- *
443
- * @v xfer		FTP data transfer interface
444
- * @v rc		Reason for close
445
- */
446
-static void ftp_xfer_closed ( struct xfer_interface *xfer, int rc ) {
447
-	struct ftp_request *ftp =
448
-		container_of ( xfer, struct ftp_request, xfer );
449
-
450
-	DBGC ( ftp, "FTP %p data transfer interface closed: %s\n",
451
-	       ftp, strerror ( rc ) );
452
-	
453
-	ftp_done ( ftp, rc );
454
-}
455
-
456
 /** FTP data transfer interface operations */
419
 /** FTP data transfer interface operations */
457
-static struct xfer_interface_operations ftp_xfer_operations = {
458
-	.close		= ftp_xfer_closed,
459
-	.vredirect	= ignore_xfer_vredirect,
460
-	.window		= unlimited_xfer_window,
461
-	.alloc_iob	= default_xfer_alloc_iob,
462
-	.deliver_iob	= xfer_deliver_as_raw,
463
-	.deliver_raw	= ignore_xfer_deliver_raw,
420
+static struct interface_operation ftp_xfer_operations[] = {
421
+	INTF_OP ( intf_close, struct ftp_request *, ftp_done ),
464
 };
422
 };
465
 
423
 
424
+/** FTP data transfer interface descriptor */
425
+static struct interface_descriptor ftp_xfer_desc =
426
+	INTF_DESC ( struct ftp_request, xfer, ftp_xfer_operations );
427
+
466
 /*****************************************************************************
428
 /*****************************************************************************
467
  *
429
  *
468
  * URI opener
430
  * URI opener
476
  * @v uri		Uniform Resource Identifier
438
  * @v uri		Uniform Resource Identifier
477
  * @ret rc		Return status code
439
  * @ret rc		Return status code
478
  */
440
  */
479
-static int ftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
441
+static int ftp_open ( struct interface *xfer, struct uri *uri ) {
480
 	struct ftp_request *ftp;
442
 	struct ftp_request *ftp;
481
 	struct sockaddr_tcpip server;
443
 	struct sockaddr_tcpip server;
482
 	int rc;
444
 	int rc;
492
 	if ( ! ftp )
454
 	if ( ! ftp )
493
 		return -ENOMEM;
455
 		return -ENOMEM;
494
 	ref_init ( &ftp->refcnt, ftp_free );
456
 	ref_init ( &ftp->refcnt, ftp_free );
495
-	xfer_init ( &ftp->xfer, &ftp_xfer_operations, &ftp->refcnt );
457
+	intf_init ( &ftp->xfer, &ftp_xfer_desc, &ftp->refcnt );
458
+	intf_init ( &ftp->control, &ftp_control_desc, &ftp->refcnt );
459
+	intf_init ( &ftp->data, &ftp_data_desc, &ftp->refcnt );
496
 	ftp->uri = uri_get ( uri );
460
 	ftp->uri = uri_get ( uri );
497
-	xfer_init ( &ftp->control, &ftp_control_operations, &ftp->refcnt );
498
-	xfer_init ( &ftp->data, &ftp_data_operations, &ftp->refcnt );
499
 	ftp->recvbuf = ftp->status_text;
461
 	ftp->recvbuf = ftp->status_text;
500
 	ftp->recvsize = sizeof ( ftp->status_text ) - 1;
462
 	ftp->recvsize = sizeof ( ftp->status_text ) - 1;
501
 
463
 
510
 		goto err;
472
 		goto err;
511
 
473
 
512
 	/* Attach to parent interface, mortalise self, and return */
474
 	/* Attach to parent interface, mortalise self, and return */
513
-	xfer_plug_plug ( &ftp->xfer, xfer );
475
+	intf_plug_plug ( &ftp->xfer, xfer );
514
 	ref_put ( &ftp->refcnt );
476
 	ref_put ( &ftp->refcnt );
515
 	return 0;
477
 	return 0;
516
 
478
 

+ 29
- 66
src/net/tcp/http.c View File

64
 	/** Reference count */
64
 	/** Reference count */
65
 	struct refcnt refcnt;
65
 	struct refcnt refcnt;
66
 	/** Data transfer interface */
66
 	/** Data transfer interface */
67
-	struct xfer_interface xfer;
67
+	struct interface xfer;
68
 
68
 
69
 	/** URI being fetched */
69
 	/** URI being fetched */
70
 	struct uri *uri;
70
 	struct uri *uri;
71
 	/** Transport layer interface */
71
 	/** Transport layer interface */
72
-	struct xfer_interface socket;
72
+	struct interface socket;
73
 
73
 
74
 	/** TX process */
74
 	/** TX process */
75
 	struct process process;
75
 	struct process process;
125
 	process_del ( &http->process );
125
 	process_del ( &http->process );
126
 
126
 
127
 	/* Close all data transfer interfaces */
127
 	/* Close all data transfer interfaces */
128
-	xfer_nullify ( &http->socket );
129
-	xfer_close ( &http->socket, rc );
130
-	xfer_nullify ( &http->xfer );
131
-	xfer_close ( &http->xfer, rc );
128
+	intf_shutdown ( &http->socket, rc );
129
+	intf_shutdown ( &http->xfer, rc );
132
 }
130
 }
133
 
131
 
134
 /**
132
 /**
349
 /**
347
 /**
350
  * Handle new data arriving via HTTP connection
348
  * Handle new data arriving via HTTP connection
351
  *
349
  *
352
- * @v socket		Transport layer interface
350
+ * @v http		HTTP request
353
  * @v iobuf		I/O buffer
351
  * @v iobuf		I/O buffer
354
  * @v meta		Data transfer metadata
352
  * @v meta		Data transfer metadata
355
  * @ret rc		Return status code
353
  * @ret rc		Return status code
356
  */
354
  */
357
-static int http_socket_deliver_iob ( struct xfer_interface *socket,
358
-				     struct io_buffer *iobuf,
359
-				     struct xfer_metadata *meta __unused ) {
360
-	struct http_request *http =
361
-		container_of ( socket, struct http_request, socket );
355
+static int http_socket_deliver ( struct http_request *http,
356
+				 struct io_buffer *iobuf,
357
+				 struct xfer_metadata *meta __unused ) {
362
 	struct http_line_handler *lh;
358
 	struct http_line_handler *lh;
363
 	char *line;
359
 	char *line;
364
 	ssize_t len;
360
 	ssize_t len;
469
 	}
465
 	}
470
 }
466
 }
471
 
467
 
472
-/**
473
- * HTTP connection closed by network stack
474
- *
475
- * @v socket		Transport layer interface
476
- * @v rc		Reason for close
477
- */
478
-static void http_socket_close ( struct xfer_interface *socket, int rc ) {
479
-	struct http_request *http =
480
-		container_of ( socket, struct http_request, socket );
481
-
482
-	DBGC ( http, "HTTP %p socket closed: %s\n",
483
-	       http, strerror ( rc ) );
484
-	
485
-	http_done ( http, rc );
486
-}
487
-
488
-/** HTTP socket operations */
489
-static struct xfer_interface_operations http_socket_operations = {
490
-	.close		= http_socket_close,
491
-	.vredirect	= xfer_vreopen,
492
-	.window		= unlimited_xfer_window,
493
-	.alloc_iob	= default_xfer_alloc_iob,
494
-	.deliver_iob	= http_socket_deliver_iob,
495
-	.deliver_raw	= xfer_deliver_as_iob,
468
+/** HTTP socket interface operations */
469
+static struct interface_operation http_socket_operations[] = {
470
+	INTF_OP ( xfer_deliver, struct http_request *, http_socket_deliver ),
471
+	INTF_OP ( intf_close, struct http_request *, http_done ),
496
 };
472
 };
497
 
473
 
498
-/**
499
- * Close HTTP data transfer interface
500
- *
501
- * @v xfer		Data transfer interface
502
- * @v rc		Reason for close
503
- */
504
-static void http_xfer_close ( struct xfer_interface *xfer, int rc ) {
505
-	struct http_request *http =
506
-		container_of ( xfer, struct http_request, xfer );
507
-
508
-	DBGC ( http, "HTTP %p interface closed: %s\n",
509
-	       http, strerror ( rc ) );
510
-
511
-	http_done ( http, rc );
512
-}
474
+/** HTTP socket interface descriptor */
475
+static struct interface_descriptor http_socket_desc =
476
+	INTF_DESC ( struct http_request, socket, http_socket_operations );
513
 
477
 
514
 /** HTTP data transfer interface operations */
478
 /** HTTP data transfer interface operations */
515
-static struct xfer_interface_operations http_xfer_operations = {
516
-	.close		= http_xfer_close,
517
-	.vredirect	= ignore_xfer_vredirect,
518
-	.window		= unlimited_xfer_window,
519
-	.alloc_iob	= default_xfer_alloc_iob,
520
-	.deliver_iob	= xfer_deliver_as_raw,
521
-	.deliver_raw	= ignore_xfer_deliver_raw,
479
+static struct interface_operation http_xfer_operations[] = {
480
+	INTF_OP ( intf_close, struct http_request *, http_done ),
522
 };
481
 };
523
 
482
 
483
+/** HTTP data transfer interface descriptor */
484
+static struct interface_descriptor http_xfer_desc =
485
+	INTF_DESC ( struct http_request, xfer, http_xfer_operations );
486
+
524
 /**
487
 /**
525
  * Initiate an HTTP connection, with optional filter
488
  * Initiate an HTTP connection, with optional filter
526
  *
489
  *
530
  * @v filter		Filter to apply to socket, or NULL
493
  * @v filter		Filter to apply to socket, or NULL
531
  * @ret rc		Return status code
494
  * @ret rc		Return status code
532
  */
495
  */
533
-int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
496
+int http_open_filter ( struct interface *xfer, struct uri *uri,
534
 		       unsigned int default_port,
497
 		       unsigned int default_port,
535
-		       int ( * filter ) ( struct xfer_interface *xfer,
536
-					  struct xfer_interface **next ) ) {
498
+		       int ( * filter ) ( struct interface *xfer,
499
+					  struct interface **next ) ) {
537
 	struct http_request *http;
500
 	struct http_request *http;
538
 	struct sockaddr_tcpip server;
501
 	struct sockaddr_tcpip server;
539
-	struct xfer_interface *socket;
502
+	struct interface *socket;
540
 	int rc;
503
 	int rc;
541
 
504
 
542
 	/* Sanity checks */
505
 	/* Sanity checks */
548
 	if ( ! http )
511
 	if ( ! http )
549
 		return -ENOMEM;
512
 		return -ENOMEM;
550
 	ref_init ( &http->refcnt, http_free );
513
 	ref_init ( &http->refcnt, http_free );
551
-	xfer_init ( &http->xfer, &http_xfer_operations, &http->refcnt );
514
+	intf_init ( &http->xfer, &http_xfer_desc, &http->refcnt );
552
        	http->uri = uri_get ( uri );
515
        	http->uri = uri_get ( uri );
553
-	xfer_init ( &http->socket, &http_socket_operations, &http->refcnt );
516
+	intf_init ( &http->socket, &http_socket_desc, &http->refcnt );
554
 	process_init ( &http->process, http_step, &http->refcnt );
517
 	process_init ( &http->process, http_step, &http->refcnt );
555
 
518
 
556
 	/* Open socket */
519
 	/* Open socket */
567
 		goto err;
530
 		goto err;
568
 
531
 
569
 	/* Attach to parent interface, mortalise self, and return */
532
 	/* Attach to parent interface, mortalise self, and return */
570
-	xfer_plug_plug ( &http->xfer, xfer );
533
+	intf_plug_plug ( &http->xfer, xfer );
571
 	ref_put ( &http->refcnt );
534
 	ref_put ( &http->refcnt );
572
 	return 0;
535
 	return 0;
573
 
536
 
586
  * @v uri		Uniform Resource Identifier
549
  * @v uri		Uniform Resource Identifier
587
  * @ret rc		Return status code
550
  * @ret rc		Return status code
588
  */
551
  */
589
-static int http_open ( struct xfer_interface *xfer, struct uri *uri ) {
552
+static int http_open ( struct interface *xfer, struct uri *uri ) {
590
 	return http_open_filter ( xfer, uri, HTTP_PORT, NULL );
553
 	return http_open_filter ( xfer, uri, HTTP_PORT, NULL );
591
 }
554
 }
592
 
555
 

+ 1
- 1
src/net/tcp/https.c View File

40
  * @v uri		Uniform Resource Identifier
40
  * @v uri		Uniform Resource Identifier
41
  * @ret rc		Return status code
41
  * @ret rc		Return status code
42
  */
42
  */
43
-static int https_open ( struct xfer_interface *xfer, struct uri *uri ) {
43
+static int https_open ( struct interface *xfer, struct uri *uri ) {
44
 	return http_open_filter ( xfer, uri, HTTPS_PORT, add_tls );
44
 	return http_open_filter ( xfer, uri, HTTPS_PORT, add_tls );
45
 }
45
 }
46
 
46
 

+ 38
- 37
src/net/tcp/iscsi.c View File

27
 #include <byteswap.h>
27
 #include <byteswap.h>
28
 #include <ipxe/vsprintf.h>
28
 #include <ipxe/vsprintf.h>
29
 #include <ipxe/socket.h>
29
 #include <ipxe/socket.h>
30
+#include <ipxe/iobuf.h>
30
 #include <ipxe/xfer.h>
31
 #include <ipxe/xfer.h>
31
 #include <ipxe/open.h>
32
 #include <ipxe/open.h>
32
 #include <ipxe/scsi.h>
33
 #include <ipxe/scsi.h>
199
 static void iscsi_close_connection ( struct iscsi_session *iscsi, int rc ) {
200
 static void iscsi_close_connection ( struct iscsi_session *iscsi, int rc ) {
200
 
201
 
201
 	/* Close all data transfer interfaces */
202
 	/* Close all data transfer interfaces */
202
-	xfer_close ( &iscsi->socket, rc );
203
+	intf_restart ( &iscsi->socket, rc );
203
 
204
 
204
 	/* Clear connection status */
205
 	/* Clear connection status */
205
 	iscsi->status = 0;
206
 	iscsi->status = 0;
1435
 /**
1436
 /**
1436
  * Receive new data
1437
  * Receive new data
1437
  *
1438
  *
1438
- * @v socket		Transport layer interface
1439
- * @v data		Received data
1440
- * @v len		Length of received data
1439
+ * @v iscsi		iSCSI session
1440
+ * @v iobuf		I/O buffer
1441
+ * @v meta		Data transfer metadata
1441
  * @ret rc		Return status code
1442
  * @ret rc		Return status code
1442
  *
1443
  *
1443
  * This handles received PDUs.  The receive strategy is to fill in
1444
  * This handles received PDUs.  The receive strategy is to fill in
1447
  * always has a full copy of the BHS available, even for portions of
1448
  * always has a full copy of the BHS available, even for portions of
1448
  * the data in different packets to the BHS.
1449
  * the data in different packets to the BHS.
1449
  */
1450
  */
1450
-static int iscsi_socket_deliver_raw ( struct xfer_interface *socket,
1451
-				      const void *data, size_t len ) {
1452
-	struct iscsi_session *iscsi =
1453
-		container_of ( socket, struct iscsi_session, socket );
1451
+static int iscsi_socket_deliver ( struct iscsi_session *iscsi,
1452
+				  struct io_buffer *iobuf,
1453
+				  struct xfer_metadata *meta __unused ) {
1454
 	struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1454
 	struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1455
 	int ( * rx ) ( struct iscsi_session *iscsi, const void *data,
1455
 	int ( * rx ) ( struct iscsi_session *iscsi, const void *data,
1456
 		       size_t len, size_t remaining );
1456
 		       size_t len, size_t remaining );
1483
 			break;
1483
 			break;
1484
 		default:
1484
 		default:
1485
 			assert ( 0 );
1485
 			assert ( 0 );
1486
-			return -EINVAL;
1486
+			rc = -EINVAL;
1487
+			goto done;
1487
 		}
1488
 		}
1488
 
1489
 
1489
 		frag_len = iscsi->rx_len - iscsi->rx_offset;
1490
 		frag_len = iscsi->rx_len - iscsi->rx_offset;
1490
-		if ( frag_len > len )
1491
-			frag_len = len;
1491
+		if ( frag_len > iob_len ( iobuf ) )
1492
+			frag_len = iob_len ( iobuf );
1492
 		remaining = iscsi->rx_len - iscsi->rx_offset - frag_len;
1493
 		remaining = iscsi->rx_len - iscsi->rx_offset - frag_len;
1493
-		if ( ( rc = rx ( iscsi, data, frag_len, remaining ) ) != 0 ) {
1494
+		if ( ( rc = rx ( iscsi, iobuf->data, frag_len,
1495
+				 remaining ) ) != 0 ) {
1494
 			DBGC ( iscsi, "iSCSI %p could not process received "
1496
 			DBGC ( iscsi, "iSCSI %p could not process received "
1495
 			       "data: %s\n", iscsi, strerror ( rc ) );
1497
 			       "data: %s\n", iscsi, strerror ( rc ) );
1496
 			iscsi_close_connection ( iscsi, rc );
1498
 			iscsi_close_connection ( iscsi, rc );
1497
 			iscsi_scsi_done ( iscsi, rc );
1499
 			iscsi_scsi_done ( iscsi, rc );
1498
-			return rc;
1500
+			goto done;
1499
 		}
1501
 		}
1500
 
1502
 
1501
 		iscsi->rx_offset += frag_len;
1503
 		iscsi->rx_offset += frag_len;
1502
-		data += frag_len;
1503
-		len -= frag_len;
1504
+		iob_pull ( iobuf, frag_len );
1504
 
1505
 
1505
 		/* If all the data for this state has not yet been
1506
 		/* If all the data for this state has not yet been
1506
 		 * received, stay in this state for now.
1507
 		 * received, stay in this state for now.
1507
 		 */
1508
 		 */
1508
-		if ( iscsi->rx_offset != iscsi->rx_len )
1509
-			return 0;
1509
+		if ( iscsi->rx_offset != iscsi->rx_len ) {
1510
+			rc = 0;
1511
+			goto done;
1512
+		}
1510
 
1513
 
1511
 		iscsi->rx_state = next_state;
1514
 		iscsi->rx_state = next_state;
1512
 		iscsi->rx_offset = 0;
1515
 		iscsi->rx_offset = 0;
1513
 	}
1516
 	}
1514
 
1517
 
1515
-	return 0;
1518
+ done:
1519
+	/* Free I/O buffer */
1520
+	free_iob ( iobuf );
1521
+	return rc;
1516
 }
1522
 }
1517
 
1523
 
1518
 /**
1524
 /**
1519
  * Handle stream connection closure
1525
  * Handle stream connection closure
1520
  *
1526
  *
1521
- * @v socket		Transport layer interface
1527
+ * @v iscsi		iSCSI session
1522
  * @v rc		Reason for close
1528
  * @v rc		Reason for close
1523
  *
1529
  *
1524
  */
1530
  */
1525
-static void iscsi_socket_close ( struct xfer_interface *socket, int rc ) {
1526
-	struct iscsi_session *iscsi =
1527
-		container_of ( socket, struct iscsi_session, socket );
1531
+static void iscsi_socket_close ( struct iscsi_session *iscsi, int rc ) {
1528
 
1532
 
1529
 	/* Even a graceful close counts as an error for iSCSI */
1533
 	/* Even a graceful close counts as an error for iSCSI */
1530
 	if ( ! rc )
1534
 	if ( ! rc )
1552
 /**
1556
 /**
1553
  * Handle redirection event
1557
  * Handle redirection event
1554
  *
1558
  *
1555
- * @v socket		Transport layer interface
1559
+ * @v iscsi		iSCSI session
1556
  * @v type		Location type
1560
  * @v type		Location type
1557
  * @v args		Remaining arguments depend upon location type
1561
  * @v args		Remaining arguments depend upon location type
1558
  * @ret rc		Return status code
1562
  * @ret rc		Return status code
1559
  */
1563
  */
1560
-static int iscsi_vredirect ( struct xfer_interface *socket, int type,
1564
+static int iscsi_vredirect ( struct iscsi_session *iscsi, int type,
1561
 			     va_list args ) {
1565
 			     va_list args ) {
1562
-	struct iscsi_session *iscsi =
1563
-		container_of ( socket, struct iscsi_session, socket );
1564
 	va_list tmp;
1566
 	va_list tmp;
1565
 	struct sockaddr *peer;
1567
 	struct sockaddr *peer;
1566
 
1568
 
1578
 		va_end ( tmp );
1580
 		va_end ( tmp );
1579
 	}
1581
 	}
1580
 
1582
 
1581
-	return xfer_vreopen ( socket, type, args );
1583
+	return xfer_vreopen ( &iscsi->socket, type, args );
1582
 }
1584
 }
1583
 			     
1585
 			     
1584
 
1586
 
1585
-/** iSCSI socket operations */
1586
-static struct xfer_interface_operations iscsi_socket_operations = {
1587
-	.close		= iscsi_socket_close,
1588
-	.vredirect	= iscsi_vredirect,
1589
-	.window		= unlimited_xfer_window,
1590
-	.alloc_iob	= default_xfer_alloc_iob,
1591
-	.deliver_iob	= xfer_deliver_as_raw,
1592
-	.deliver_raw	= iscsi_socket_deliver_raw,
1587
+/** iSCSI socket interface operations */
1588
+static struct interface_operation iscsi_socket_operations[] = {
1589
+	INTF_OP ( xfer_deliver, struct iscsi_session *, iscsi_socket_deliver ),
1590
+	INTF_OP ( xfer_vredirect, struct iscsi_session *, iscsi_vredirect ),
1591
+	INTF_OP ( intf_close, struct iscsi_session *, iscsi_socket_close ),
1593
 };
1592
 };
1594
 
1593
 
1594
+/** iSCSI socket interface descriptor */
1595
+static struct interface_descriptor iscsi_socket_desc =
1596
+	INTF_DESC ( struct iscsi_session, socket, iscsi_socket_operations );
1595
 
1597
 
1596
 /****************************************************************************
1598
 /****************************************************************************
1597
  *
1599
  *
1641
 	struct iscsi_session *iscsi =
1643
 	struct iscsi_session *iscsi =
1642
 		container_of ( scsi->backend, struct iscsi_session, refcnt );
1644
 		container_of ( scsi->backend, struct iscsi_session, refcnt );
1643
 
1645
 
1644
-	xfer_nullify ( &iscsi->socket );
1645
 	iscsi_close_connection ( iscsi, 0 );
1646
 	iscsi_close_connection ( iscsi, 0 );
1646
 	process_del ( &iscsi->process );
1647
 	process_del ( &iscsi->process );
1647
 	scsi->command = scsi_detached_command;
1648
 	scsi->command = scsi_detached_command;
1793
 	if ( ! iscsi )
1794
 	if ( ! iscsi )
1794
 		return -ENOMEM;
1795
 		return -ENOMEM;
1795
 	ref_init ( &iscsi->refcnt, iscsi_free );
1796
 	ref_init ( &iscsi->refcnt, iscsi_free );
1796
-	xfer_init ( &iscsi->socket, &iscsi_socket_operations, &iscsi->refcnt );
1797
+	intf_init ( &iscsi->socket, &iscsi_socket_desc, &iscsi->refcnt );
1797
 	process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
1798
 	process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
1798
 
1799
 
1799
 	/* Parse root path */
1800
 	/* Parse root path */

+ 72
- 92
src/net/tls.c View File

35
 #include <ipxe/sha1.h>
35
 #include <ipxe/sha1.h>
36
 #include <ipxe/aes.h>
36
 #include <ipxe/aes.h>
37
 #include <ipxe/rsa.h>
37
 #include <ipxe/rsa.h>
38
+#include <ipxe/iobuf.h>
38
 #include <ipxe/xfer.h>
39
 #include <ipxe/xfer.h>
39
 #include <ipxe/open.h>
40
 #include <ipxe/open.h>
40
-#include <ipxe/filter.h>
41
 #include <ipxe/asn1.h>
41
 #include <ipxe/asn1.h>
42
 #include <ipxe/x509.h>
42
 #include <ipxe/x509.h>
43
 #include <ipxe/tls.h>
43
 #include <ipxe/tls.h>
107
 	process_del ( &tls->process );
107
 	process_del ( &tls->process );
108
 	
108
 	
109
 	/* Close ciphertext and plaintext streams */
109
 	/* Close ciphertext and plaintext streams */
110
-	xfer_nullify ( &tls->cipherstream.xfer );
111
-	xfer_close ( &tls->cipherstream.xfer, rc );
112
-	xfer_nullify ( &tls->plainstream.xfer );
113
-	xfer_close ( &tls->plainstream.xfer, rc );
110
+	intf_shutdown ( &tls->cipherstream, rc );
111
+	intf_shutdown ( &tls->plainstream, rc );
114
 }
112
 }
115
 
113
 
116
 /******************************************************************************
114
 /******************************************************************************
1030
 	case TLS_TYPE_HANDSHAKE:
1028
 	case TLS_TYPE_HANDSHAKE:
1031
 		return tls_new_handshake ( tls, data, len );
1029
 		return tls_new_handshake ( tls, data, len );
1032
 	case TLS_TYPE_DATA:
1030
 	case TLS_TYPE_DATA:
1033
-		return xfer_deliver_raw ( &tls->plainstream.xfer, data, len );
1031
+		return xfer_deliver_raw ( &tls->plainstream, data, len );
1034
 	default:
1032
 	default:
1035
 		/* RFC4346 says that we should just ignore unknown
1033
 		/* RFC4346 says that we should just ignore unknown
1036
 		 * record types.
1034
 		 * record types.
1209
 
1207
 
1210
 	/* Allocate ciphertext */
1208
 	/* Allocate ciphertext */
1211
 	ciphertext_len = ( sizeof ( *tlshdr ) + plaintext_len );
1209
 	ciphertext_len = ( sizeof ( *tlshdr ) + plaintext_len );
1212
-	ciphertext = xfer_alloc_iob ( &tls->cipherstream.xfer,
1213
-				      ciphertext_len );
1210
+	ciphertext = xfer_alloc_iob ( &tls->cipherstream, ciphertext_len );
1214
 	if ( ! ciphertext ) {
1211
 	if ( ! ciphertext ) {
1215
 		DBGC ( tls, "TLS %p could not allocate %zd bytes for "
1212
 		DBGC ( tls, "TLS %p could not allocate %zd bytes for "
1216
 		       "ciphertext\n", tls, ciphertext_len );
1213
 		       "ciphertext\n", tls, ciphertext_len );
1234
 	plaintext = NULL;
1231
 	plaintext = NULL;
1235
 
1232
 
1236
 	/* Send ciphertext */
1233
 	/* Send ciphertext */
1237
-	rc = xfer_deliver_iob ( &tls->cipherstream.xfer, ciphertext );
1238
-	ciphertext = NULL;
1239
-	if ( rc != 0 ) {
1234
+	if ( ( rc = xfer_deliver_iob ( &tls->cipherstream,
1235
+				       iob_disown ( ciphertext ) ) ) != 0 ) {
1240
 		DBGC ( tls, "TLS %p could not deliver ciphertext: %s\n",
1236
 		DBGC ( tls, "TLS %p could not deliver ciphertext: %s\n",
1241
 		       tls, strerror ( rc ) );
1237
 		       tls, strerror ( rc ) );
1242
 		goto done;
1238
 		goto done;
1435
  ******************************************************************************
1431
  ******************************************************************************
1436
  */
1432
  */
1437
 
1433
 
1438
-/**
1439
- * Close interface
1440
- *
1441
- * @v xfer		Plainstream data transfer interface
1442
- * @v rc		Reason for close
1443
- */
1444
-static void tls_plainstream_close ( struct xfer_interface *xfer, int rc ) {
1445
-	struct tls_session *tls =
1446
-		container_of ( xfer, struct tls_session, plainstream.xfer );
1447
-
1448
-	tls_close ( tls, rc );
1449
-}
1450
-
1451
 /**
1434
 /**
1452
  * Check flow control window
1435
  * Check flow control window
1453
  *
1436
  *
1454
- * @v xfer		Plainstream data transfer interface
1437
+ * @v tls		TLS session
1455
  * @ret len		Length of window
1438
  * @ret len		Length of window
1456
  */
1439
  */
1457
-static size_t tls_plainstream_window ( struct xfer_interface *xfer ) {
1458
-	struct tls_session *tls =
1459
-		container_of ( xfer, struct tls_session, plainstream.xfer );
1440
+static size_t tls_plainstream_window ( struct tls_session *tls ) {
1460
 
1441
 
1461
 	/* Block window unless we are ready to accept data */
1442
 	/* Block window unless we are ready to accept data */
1462
 	if ( tls->tx_state != TLS_TX_DATA )
1443
 	if ( tls->tx_state != TLS_TX_DATA )
1463
 		return 0;
1444
 		return 0;
1464
 
1445
 
1465
-	return filter_window ( xfer );
1446
+	return xfer_window ( &tls->cipherstream );
1466
 }
1447
 }
1467
 
1448
 
1468
 /**
1449
 /**
1469
  * Deliver datagram as raw data
1450
  * Deliver datagram as raw data
1470
  *
1451
  *
1471
- * @v xfer		Plainstream data transfer interface
1472
- * @v data		Data buffer
1473
- * @v len		Length of data buffer
1452
+ * @v tls		TLS session
1453
+ * @v iobuf		I/O buffer
1454
+ * @v meta		Data transfer metadata
1474
  * @ret rc		Return status code
1455
  * @ret rc		Return status code
1475
  */
1456
  */
1476
-static int tls_plainstream_deliver_raw ( struct xfer_interface *xfer,
1477
-					 const void *data, size_t len ) {
1478
-	struct tls_session *tls =
1479
-		container_of ( xfer, struct tls_session, plainstream.xfer );
1457
+static int tls_plainstream_deliver ( struct tls_session *tls,
1458
+				     struct io_buffer *iobuf,
1459
+				     struct xfer_metadata *meta __unused ) {
1460
+	int rc;
1480
 	
1461
 	
1481
 	/* Refuse unless we are ready to accept data */
1462
 	/* Refuse unless we are ready to accept data */
1482
-	if ( tls->tx_state != TLS_TX_DATA )
1483
-		return -ENOTCONN;
1463
+	if ( tls->tx_state != TLS_TX_DATA ) {
1464
+		rc = -ENOTCONN;
1465
+		goto done;
1466
+	}
1467
+
1468
+	if ( ( rc = tls_send_plaintext ( tls, TLS_TYPE_DATA, iobuf->data,
1469
+					 iob_len ( iobuf ) ) ) != 0 )
1470
+		goto done;
1484
 
1471
 
1485
-	return tls_send_plaintext ( tls, TLS_TYPE_DATA, data, len );
1472
+ done:
1473
+	free_iob ( iobuf );
1474
+	return rc;
1486
 }
1475
 }
1487
 
1476
 
1488
-/** TLS plaintext stream operations */
1489
-static struct xfer_interface_operations tls_plainstream_operations = {
1490
-	.close		= tls_plainstream_close,
1491
-	.vredirect	= ignore_xfer_vredirect,
1492
-	.window		= tls_plainstream_window,
1493
-	.alloc_iob	= default_xfer_alloc_iob,
1494
-	.deliver_iob	= xfer_deliver_as_raw,
1495
-	.deliver_raw	= tls_plainstream_deliver_raw,
1477
+/** TLS plaintext stream interface operations */
1478
+static struct interface_operation tls_plainstream_ops[] = {
1479
+	INTF_OP ( xfer_deliver, struct tls_session *, tls_plainstream_deliver ),
1480
+	INTF_OP ( xfer_window, struct tls_session *, tls_plainstream_window ),
1481
+	INTF_OP ( intf_close, struct tls_session *, tls_close ),
1496
 };
1482
 };
1497
 
1483
 
1484
+/** TLS plaintext stream interface descriptor */
1485
+static struct interface_descriptor tls_plainstream_desc =
1486
+	INTF_DESC_PASSTHRU ( struct tls_session, plainstream,
1487
+			     tls_plainstream_ops, cipherstream );
1488
+
1498
 /******************************************************************************
1489
 /******************************************************************************
1499
  *
1490
  *
1500
  * Ciphertext stream operations
1491
  * Ciphertext stream operations
1502
  ******************************************************************************
1493
  ******************************************************************************
1503
  */
1494
  */
1504
 
1495
 
1505
-/**
1506
- * Close interface
1507
- *
1508
- * @v xfer		Plainstream data transfer interface
1509
- * @v rc		Reason for close
1510
- */
1511
-static void tls_cipherstream_close ( struct xfer_interface *xfer, int rc ) {
1512
-	struct tls_session *tls =
1513
-		container_of ( xfer, struct tls_session, cipherstream.xfer );
1514
-
1515
-	tls_close ( tls, rc );
1516
-}
1517
-
1518
 /**
1496
 /**
1519
  * Handle received TLS header
1497
  * Handle received TLS header
1520
  *
1498
  *
1569
 /**
1547
 /**
1570
  * Receive new ciphertext
1548
  * Receive new ciphertext
1571
  *
1549
  *
1572
- * @v app		Stream application
1573
- * @v data		Data received
1574
- * @v len		Length of received data
1550
+ * @v tls		TLS session
1551
+ * @v iobuf		I/O buffer
1552
+ * @v meta		Data transfer metadat
1575
  * @ret rc		Return status code
1553
  * @ret rc		Return status code
1576
  */
1554
  */
1577
-static int tls_cipherstream_deliver_raw ( struct xfer_interface *xfer,
1578
-					  const void *data, size_t len ) {
1579
-	struct tls_session *tls = 
1580
-		container_of ( xfer, struct tls_session, cipherstream.xfer );
1555
+static int tls_cipherstream_deliver ( struct tls_session *tls,
1556
+				      struct io_buffer *iobuf,
1557
+				      struct xfer_metadata *xfer __unused ) {
1581
 	size_t frag_len;
1558
 	size_t frag_len;
1582
 	void *buf;
1559
 	void *buf;
1583
 	size_t buf_len;
1560
 	size_t buf_len;
1584
 	int ( * process ) ( struct tls_session *tls );
1561
 	int ( * process ) ( struct tls_session *tls );
1585
 	int rc;
1562
 	int rc;
1586
 
1563
 
1587
-	while ( len ) {
1564
+	while ( iob_len ( iobuf ) ) {
1588
 		/* Select buffer according to current state */
1565
 		/* Select buffer according to current state */
1589
 		switch ( tls->rx_state ) {
1566
 		switch ( tls->rx_state ) {
1590
 		case TLS_RX_HEADER:
1567
 		case TLS_RX_HEADER:
1599
 			break;
1576
 			break;
1600
 		default:
1577
 		default:
1601
 			assert ( 0 );
1578
 			assert ( 0 );
1602
-			return -EINVAL;
1579
+			rc = -EINVAL;
1580
+			goto done;
1603
 		}
1581
 		}
1604
 
1582
 
1605
 		/* Copy data portion to buffer */
1583
 		/* Copy data portion to buffer */
1606
 		frag_len = ( buf_len - tls->rx_rcvd );
1584
 		frag_len = ( buf_len - tls->rx_rcvd );
1607
-		if ( frag_len > len )
1608
-			frag_len = len;
1609
-		memcpy ( ( buf + tls->rx_rcvd ), data, frag_len );
1585
+		if ( frag_len > iob_len  ( iobuf ) )
1586
+			frag_len = iob_len ( iobuf );
1587
+		memcpy ( ( buf + tls->rx_rcvd ), iobuf->data, frag_len );
1610
 		tls->rx_rcvd += frag_len;
1588
 		tls->rx_rcvd += frag_len;
1611
-		data += frag_len;
1612
-		len -= frag_len;
1589
+		iob_pull ( iobuf, frag_len );
1613
 
1590
 
1614
 		/* Process data if buffer is now full */
1591
 		/* Process data if buffer is now full */
1615
 		if ( tls->rx_rcvd == buf_len ) {
1592
 		if ( tls->rx_rcvd == buf_len ) {
1616
 			if ( ( rc = process ( tls ) ) != 0 ) {
1593
 			if ( ( rc = process ( tls ) ) != 0 ) {
1617
 				tls_close ( tls, rc );
1594
 				tls_close ( tls, rc );
1618
-				return rc;
1595
+				goto done;
1619
 			}
1596
 			}
1620
 			tls->rx_rcvd = 0;
1597
 			tls->rx_rcvd = 0;
1621
 		}
1598
 		}
1622
 	}
1599
 	}
1600
+	rc = 0;
1623
 
1601
 
1624
-	return 0;
1602
+ done:
1603
+	free_iob ( iobuf );
1604
+	return rc;
1625
 }
1605
 }
1626
 
1606
 
1627
-/** TLS ciphertext stream operations */
1628
-static struct xfer_interface_operations tls_cipherstream_operations = {
1629
-	.close		= tls_cipherstream_close,
1630
-	.vredirect	= xfer_vreopen,
1631
-	.window		= filter_window,
1632
-	.alloc_iob	= default_xfer_alloc_iob,
1633
-	.deliver_iob	= xfer_deliver_as_raw,
1634
-	.deliver_raw	= tls_cipherstream_deliver_raw,
1607
+/** TLS ciphertext stream interface operations */
1608
+static struct interface_operation tls_cipherstream_ops[] = {
1609
+	INTF_OP ( xfer_deliver, struct tls_session *,
1610
+		  tls_cipherstream_deliver ),
1611
+	INTF_OP ( intf_close, struct tls_session *, tls_close ),
1635
 };
1612
 };
1636
 
1613
 
1614
+/** TLS ciphertext stream interface descriptor */
1615
+static struct interface_descriptor tls_cipherstream_desc =
1616
+	INTF_DESC_PASSTHRU ( struct tls_session, cipherstream,
1617
+			     tls_cipherstream_ops, plainstream );
1618
+
1637
 /******************************************************************************
1619
 /******************************************************************************
1638
  *
1620
  *
1639
  * Controlling process
1621
  * Controlling process
1652
 	int rc;
1634
 	int rc;
1653
 
1635
 
1654
 	/* Wait for cipherstream to become ready */
1636
 	/* Wait for cipherstream to become ready */
1655
-	if ( ! xfer_window ( &tls->cipherstream.xfer ) )
1637
+	if ( ! xfer_window ( &tls->cipherstream ) )
1656
 		return;
1638
 		return;
1657
 
1639
 
1658
 	switch ( tls->tx_state ) {
1640
 	switch ( tls->tx_state ) {
1723
  ******************************************************************************
1705
  ******************************************************************************
1724
  */
1706
  */
1725
 
1707
 
1726
-int add_tls ( struct xfer_interface *xfer, struct xfer_interface **next ) {
1708
+int add_tls ( struct interface *xfer, struct interface **next ) {
1727
 	struct tls_session *tls;
1709
 	struct tls_session *tls;
1728
 
1710
 
1729
 	/* Allocate and initialise TLS structure */
1711
 	/* Allocate and initialise TLS structure */
1732
 		return -ENOMEM;
1714
 		return -ENOMEM;
1733
 	memset ( tls, 0, sizeof ( *tls ) );
1715
 	memset ( tls, 0, sizeof ( *tls ) );
1734
 	ref_init ( &tls->refcnt, free_tls );
1716
 	ref_init ( &tls->refcnt, free_tls );
1735
-	filter_init ( &tls->plainstream, &tls_plainstream_operations,
1736
-		      &tls->cipherstream, &tls_cipherstream_operations,
1737
-		      &tls->refcnt );
1717
+	intf_init ( &tls->plainstream, &tls_plainstream_desc, &tls->refcnt );
1718
+	intf_init ( &tls->cipherstream, &tls_cipherstream_desc, &tls->refcnt );
1738
 	tls_clear_cipher ( tls, &tls->tx_cipherspec );
1719
 	tls_clear_cipher ( tls, &tls->tx_cipherspec );
1739
 	tls_clear_cipher ( tls, &tls->tx_cipherspec_pending );
1720
 	tls_clear_cipher ( tls, &tls->tx_cipherspec_pending );
1740
 	tls_clear_cipher ( tls, &tls->rx_cipherspec );
1721
 	tls_clear_cipher ( tls, &tls->rx_cipherspec );
1751
 	process_init ( &tls->process, tls_step, &tls->refcnt );
1732
 	process_init ( &tls->process, tls_step, &tls->refcnt );
1752
 
1733
 
1753
 	/* Attach to parent interface, mortalise self, and return */
1734
 	/* Attach to parent interface, mortalise self, and return */
1754
-	xfer_plug_plug ( &tls->plainstream.xfer, xfer );
1755
-	*next = &tls->cipherstream.xfer;
1735
+	intf_plug_plug ( &tls->plainstream, xfer );
1736
+	*next = &tls->cipherstream;
1756
 	ref_put ( &tls->refcnt );
1737
 	ref_put ( &tls->refcnt );
1757
 	return 0;
1738
 	return 0;
1758
 }
1739
 }
1759
-

+ 25
- 43
src/net/udp.c View File

29
 	struct list_head list;
29
 	struct list_head list;
30
 
30
 
31
 	/** Data transfer interface */
31
 	/** Data transfer interface */
32
-	struct xfer_interface xfer;
32
+	struct interface xfer;
33
 
33
 
34
 	/** Local socket address */
34
 	/** Local socket address */
35
 	struct sockaddr_tcpip local;
35
 	struct sockaddr_tcpip local;
43
 static LIST_HEAD ( udp_conns );
43
 static LIST_HEAD ( udp_conns );
44
 
44
 
45
 /* Forward declatations */
45
 /* Forward declatations */
46
-static struct xfer_interface_operations udp_xfer_operations;
46
+static struct interface_descriptor udp_xfer_desc;
47
 struct tcpip_protocol udp_protocol;
47
 struct tcpip_protocol udp_protocol;
48
 
48
 
49
 /**
49
 /**
97
  * @v promisc		Socket is promiscuous
97
  * @v promisc		Socket is promiscuous
98
  * @ret rc		Return status code
98
  * @ret rc		Return status code
99
  */
99
  */
100
-static int udp_open_common ( struct xfer_interface *xfer,
100
+static int udp_open_common ( struct interface *xfer,
101
 			     struct sockaddr *peer, struct sockaddr *local,
101
 			     struct sockaddr *peer, struct sockaddr *local,
102
 			     int promisc ) {
102
 			     int promisc ) {
103
 	struct sockaddr_tcpip *st_peer = ( struct sockaddr_tcpip * ) peer;
103
 	struct sockaddr_tcpip *st_peer = ( struct sockaddr_tcpip * ) peer;
111
 		return -ENOMEM;
111
 		return -ENOMEM;
112
 	DBGC ( udp, "UDP %p allocated\n", udp );
112
 	DBGC ( udp, "UDP %p allocated\n", udp );
113
 	ref_init ( &udp->refcnt, NULL );
113
 	ref_init ( &udp->refcnt, NULL );
114
-	xfer_init ( &udp->xfer, &udp_xfer_operations, &udp->refcnt );
114
+	intf_init ( &udp->xfer, &udp_xfer_desc, &udp->refcnt );
115
 	if ( st_peer )
115
 	if ( st_peer )
116
 		memcpy ( &udp->peer, st_peer, sizeof ( udp->peer ) );
116
 		memcpy ( &udp->peer, st_peer, sizeof ( udp->peer ) );
117
 	if ( st_local )
117
 	if ( st_local )
126
 	/* Attach parent interface, transfer reference to connection
126
 	/* Attach parent interface, transfer reference to connection
127
 	 * list and return
127
 	 * list and return
128
 	 */
128
 	 */
129
-	xfer_plug_plug ( &udp->xfer, xfer );
129
+	intf_plug_plug ( &udp->xfer, xfer );
130
 	list_add ( &udp->list, &udp_conns );
130
 	list_add ( &udp->list, &udp_conns );
131
 	return 0;
131
 	return 0;
132
 
132
 
143
  * @v local		Local socket address, or NULL
143
  * @v local		Local socket address, or NULL
144
  * @ret rc		Return status code
144
  * @ret rc		Return status code
145
  */
145
  */
146
-int udp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
146
+int udp_open ( struct interface *xfer, struct sockaddr *peer,
147
 	       struct sockaddr *local ) {
147
 	       struct sockaddr *local ) {
148
 	return udp_open_common ( xfer, peer, local, 0 );
148
 	return udp_open_common ( xfer, peer, local, 0 );
149
 }
149
 }
157
  * Promiscuous UDP connections are required in order to support the
157
  * Promiscuous UDP connections are required in order to support the
158
  * PXE API.
158
  * PXE API.
159
  */
159
  */
160
-int udp_open_promisc ( struct xfer_interface *xfer ) {
160
+int udp_open_promisc ( struct interface *xfer ) {
161
 	return udp_open_common ( xfer, NULL, NULL, 1 );
161
 	return udp_open_common ( xfer, NULL, NULL, 1 );
162
 }
162
 }
163
 
163
 
170
 static void udp_close ( struct udp_connection *udp, int rc ) {
170
 static void udp_close ( struct udp_connection *udp, int rc ) {
171
 
171
 
172
 	/* Close data transfer interface */
172
 	/* Close data transfer interface */
173
-	xfer_nullify ( &udp->xfer );
174
-	xfer_close ( &udp->xfer, rc );
173
+	intf_shutdown ( &udp->xfer, rc );
175
 
174
 
176
 	/* Remove from list of connections and drop list's reference */
175
 	/* Remove from list of connections and drop list's reference */
177
 	list_del ( &udp->list );
176
 	list_del ( &udp->list );
331
 	memset ( &meta, 0, sizeof ( meta ) );
330
 	memset ( &meta, 0, sizeof ( meta ) );
332
 	meta.src = ( struct sockaddr * ) st_src;
331
 	meta.src = ( struct sockaddr * ) st_src;
333
 	meta.dest = ( struct sockaddr * ) st_dest;
332
 	meta.dest = ( struct sockaddr * ) st_dest;
334
-	rc = xfer_deliver_iob_meta ( &udp->xfer, iob_disown ( iobuf ), &meta );
333
+	rc = xfer_deliver ( &udp->xfer, iob_disown ( iobuf ), &meta );
335
 
334
 
336
  done:
335
  done:
337
 	free_iob ( iobuf );
336
 	free_iob ( iobuf );
351
  ***************************************************************************
350
  ***************************************************************************
352
  */
351
  */
353
 
352
 
354
-/**
355
- * Close interface
356
- *
357
- * @v xfer		Data transfer interface
358
- * @v rc		Reason for close
359
- */
360
-static void udp_xfer_close ( struct xfer_interface *xfer, int rc ) {
361
-	struct udp_connection *udp =
362
-		container_of ( xfer, struct udp_connection, xfer );
363
-
364
-	/* Close connection */
365
-	udp_close ( udp, rc );
366
-}
367
-
368
 /**
353
 /**
369
  * Allocate I/O buffer for UDP
354
  * Allocate I/O buffer for UDP
370
  *
355
  *
371
- * @v xfer		Data transfer interface
356
+ * @v udp		UDP connection
372
  * @v len		Payload size
357
  * @v len		Payload size
373
  * @ret iobuf		I/O buffer, or NULL
358
  * @ret iobuf		I/O buffer, or NULL
374
  */
359
  */
375
-static struct io_buffer * udp_alloc_iob ( struct xfer_interface *xfer,
376
-					  size_t len ) {
377
-	struct udp_connection *udp =
378
-		container_of ( xfer, struct udp_connection, xfer );	
360
+static struct io_buffer * udp_xfer_alloc_iob ( struct udp_connection *udp,
361
+					       size_t len ) {
379
 	struct io_buffer *iobuf;
362
 	struct io_buffer *iobuf;
380
 
363
 
381
 	iobuf = alloc_iob ( UDP_MAX_HLEN + len );
364
 	iobuf = alloc_iob ( UDP_MAX_HLEN + len );
391
 /**
374
 /**
392
  * Deliver datagram as I/O buffer
375
  * Deliver datagram as I/O buffer
393
  *
376
  *
394
- * @v xfer		Data transfer interface
377
+ * @v udp		UDP connection
395
  * @v iobuf		Datagram I/O buffer
378
  * @v iobuf		Datagram I/O buffer
396
  * @v meta		Data transfer metadata
379
  * @v meta		Data transfer metadata
397
  * @ret rc		Return status code
380
  * @ret rc		Return status code
398
  */
381
  */
399
-static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
400
-				  struct io_buffer *iobuf,
401
-				  struct xfer_metadata *meta ) {
402
-	struct udp_connection *udp =
403
-		container_of ( xfer, struct udp_connection, xfer );
382
+static int udp_xfer_deliver ( struct udp_connection *udp,
383
+			      struct io_buffer *iobuf,
384
+			      struct xfer_metadata *meta ) {
404
 
385
 
405
 	/* Transmit data, if possible */
386
 	/* Transmit data, if possible */
406
 	udp_tx ( udp, iobuf, ( ( struct sockaddr_tcpip * ) meta->src ),
387
 	udp_tx ( udp, iobuf, ( ( struct sockaddr_tcpip * ) meta->src ),
410
 }
391
 }
411
 
392
 
412
 /** UDP data transfer interface operations */
393
 /** UDP data transfer interface operations */
413
-static struct xfer_interface_operations udp_xfer_operations = {
414
-	.close		= udp_xfer_close,
415
-	.vredirect	= ignore_xfer_vredirect,
416
-	.window		= unlimited_xfer_window,
417
-	.alloc_iob	= udp_alloc_iob,
418
-	.deliver_iob	= udp_xfer_deliver_iob,
419
-	.deliver_raw	= xfer_deliver_as_iob,
394
+static struct interface_operation udp_xfer_operations[] = {
395
+	INTF_OP ( xfer_deliver, struct udp_connection *, udp_xfer_deliver ),
396
+	INTF_OP ( xfer_alloc_iob, struct udp_connection *, udp_xfer_alloc_iob ),
397
+	INTF_OP ( intf_close, struct udp_connection *, udp_close ),
420
 };
398
 };
421
 
399
 
400
+/** UDP data transfer interface descriptor */
401
+static struct interface_descriptor udp_xfer_desc =
402
+	INTF_DESC ( struct udp_connection, xfer, udp_xfer_operations );
403
+
422
 /***************************************************************************
404
 /***************************************************************************
423
  *
405
  *
424
  * Openers
406
  * Openers
443
  * @v uri		URI
425
  * @v uri		URI
444
  * @ret rc		Return status code
426
  * @ret rc		Return status code
445
  */
427
  */
446
-static int udp_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
428
+static int udp_open_uri ( struct interface *xfer, struct uri *uri ) {
447
 	struct sockaddr_tcpip peer;
429
 	struct sockaddr_tcpip peer;
448
 
430
 
449
 	/* Sanity check */
431
 	/* Sanity check */

+ 17
- 20
src/net/udp/dhcp.c View File

26
 #include <assert.h>
26
 #include <assert.h>
27
 #include <byteswap.h>
27
 #include <byteswap.h>
28
 #include <ipxe/if_ether.h>
28
 #include <ipxe/if_ether.h>
29
+#include <ipxe/iobuf.h>
29
 #include <ipxe/netdevice.h>
30
 #include <ipxe/netdevice.h>
30
 #include <ipxe/device.h>
31
 #include <ipxe/device.h>
31
 #include <ipxe/xfer.h>
32
 #include <ipxe/xfer.h>
240
 	/** Job control interface */
241
 	/** Job control interface */
241
 	struct interface job;
242
 	struct interface job;
242
 	/** Data transfer interface */
243
 	/** Data transfer interface */
243
-	struct xfer_interface xfer;
244
+	struct interface xfer;
244
 
245
 
245
 	/** Network device being configured */
246
 	/** Network device being configured */
246
 	struct net_device *netdev;
247
 	struct net_device *netdev;
298
 	stop_timer ( &dhcp->timer );
299
 	stop_timer ( &dhcp->timer );
299
 
300
 
300
 	/* Shut down interfaces */
301
 	/* Shut down interfaces */
301
-	xfer_nullify ( &dhcp->xfer );
302
-	xfer_close ( &dhcp->xfer, rc );
302
+	intf_shutdown ( &dhcp->xfer, rc );
303
 	intf_shutdown ( &dhcp->job, rc );
303
 	intf_shutdown ( &dhcp->job, rc );
304
 }
304
 }
305
 
305
 
1241
 
1241
 
1242
 	/* Transmit the packet */
1242
 	/* Transmit the packet */
1243
 	iob_put ( iobuf, dhcppkt.len );
1243
 	iob_put ( iobuf, dhcppkt.len );
1244
-	if ( ( rc = xfer_deliver_iob_meta ( &dhcp->xfer, iob_disown ( iobuf ),
1245
-					    &meta ) ) != 0 ) {
1244
+	if ( ( rc = xfer_deliver ( &dhcp->xfer, iob_disown ( iobuf ),
1245
+				   &meta ) ) != 0 ) {
1246
 		DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",
1246
 		DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",
1247
 		       dhcp, strerror ( rc ) );
1247
 		       dhcp, strerror ( rc ) );
1248
 		goto done;
1248
 		goto done;
1256
 /**
1256
 /**
1257
  * Receive new data
1257
  * Receive new data
1258
  *
1258
  *
1259
- * @v xfer 		Data transfer interface
1259
+ * @v dhcp		DHCP session
1260
  * @v iobuf		I/O buffer
1260
  * @v iobuf		I/O buffer
1261
  * @v meta		Transfer metadata
1261
  * @v meta		Transfer metadata
1262
  * @ret rc		Return status code
1262
  * @ret rc		Return status code
1263
  */
1263
  */
1264
-static int dhcp_deliver_iob ( struct xfer_interface *xfer,
1265
-			      struct io_buffer *iobuf,
1266
-			      struct xfer_metadata *meta ) {
1267
-	struct dhcp_session *dhcp =
1268
-		container_of ( xfer, struct dhcp_session, xfer );
1264
+static int dhcp_deliver ( struct dhcp_session *dhcp,
1265
+			  struct io_buffer *iobuf,
1266
+			  struct xfer_metadata *meta ) {
1269
 	struct sockaddr_in *peer;
1267
 	struct sockaddr_in *peer;
1270
 	size_t data_len;
1268
 	size_t data_len;
1271
 	struct dhcp_packet *dhcppkt;
1269
 	struct dhcp_packet *dhcppkt;
1328
 }
1326
 }
1329
 
1327
 
1330
 /** DHCP data transfer interface operations */
1328
 /** DHCP data transfer interface operations */
1331
-static struct xfer_interface_operations dhcp_xfer_operations = {
1332
-	.close		= ignore_xfer_close,
1333
-	.vredirect	= xfer_vreopen,
1334
-	.window		= unlimited_xfer_window,
1335
-	.alloc_iob	= default_xfer_alloc_iob,
1336
-	.deliver_iob	= dhcp_deliver_iob,
1337
-	.deliver_raw	= xfer_deliver_as_iob,
1329
+static struct interface_operation dhcp_xfer_operations[] = {
1330
+	INTF_OP ( xfer_deliver, struct dhcp_session *, dhcp_deliver ),
1338
 };
1331
 };
1339
 
1332
 
1333
+/** DHCP data transfer interface descriptor */
1334
+static struct interface_descriptor dhcp_xfer_desc =
1335
+	INTF_DESC ( struct dhcp_session, xfer, dhcp_xfer_operations );
1336
+
1340
 /**
1337
 /**
1341
  * Handle DHCP retry timer expiry
1338
  * Handle DHCP retry timer expiry
1342
  *
1339
  *
1427
 		return -ENOMEM;
1424
 		return -ENOMEM;
1428
 	ref_init ( &dhcp->refcnt, dhcp_free );
1425
 	ref_init ( &dhcp->refcnt, dhcp_free );
1429
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1426
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1430
-	xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
1427
+	intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1431
 	timer_init ( &dhcp->timer, dhcp_timer_expired );
1428
 	timer_init ( &dhcp->timer, dhcp_timer_expired );
1432
 	dhcp->netdev = netdev_get ( netdev );
1429
 	dhcp->netdev = netdev_get ( netdev );
1433
 	dhcp->local.sin_family = AF_INET;
1430
 	dhcp->local.sin_family = AF_INET;
1530
 		return -ENOMEM;
1527
 		return -ENOMEM;
1531
 	ref_init ( &dhcp->refcnt, dhcp_free );
1528
 	ref_init ( &dhcp->refcnt, dhcp_free );
1532
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1529
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1533
-	xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
1530
+	intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1534
 	timer_init ( &dhcp->timer, dhcp_timer_expired );
1531
 	timer_init ( &dhcp->timer, dhcp_timer_expired );
1535
 	dhcp->netdev = netdev_get ( netdev );
1532
 	dhcp->netdev = netdev_get ( netdev );
1536
 	dhcp->local.sin_family = AF_INET;
1533
 	dhcp->local.sin_family = AF_INET;

+ 45
- 36
src/net/udp/dns.c View File

28
 #include <errno.h>
28
 #include <errno.h>
29
 #include <byteswap.h>
29
 #include <byteswap.h>
30
 #include <ipxe/refcnt.h>
30
 #include <ipxe/refcnt.h>
31
+#include <ipxe/iobuf.h>
31
 #include <ipxe/xfer.h>
32
 #include <ipxe/xfer.h>
32
 #include <ipxe/open.h>
33
 #include <ipxe/open.h>
33
 #include <ipxe/resolv.h>
34
 #include <ipxe/resolv.h>
60
 	/** Name resolution interface */
61
 	/** Name resolution interface */
61
 	struct interface resolv;
62
 	struct interface resolv;
62
 	/** Data transfer interface */
63
 	/** Data transfer interface */
63
-	struct xfer_interface socket;
64
+	struct interface socket;
64
 	/** Retry timer */
65
 	/** Retry timer */
65
 	struct retry_timer timer;
66
 	struct retry_timer timer;
66
 
67
 
89
 	/* Stop the retry timer */
90
 	/* Stop the retry timer */
90
 	stop_timer ( &dns->timer );
91
 	stop_timer ( &dns->timer );
91
 
92
 
92
-	/* Close data transfer interface */
93
-	xfer_nullify ( &dns->socket );
94
-	xfer_close ( &dns->socket, rc );
95
-
96
 	/* Shut down interfaces */
93
 	/* Shut down interfaces */
94
+	intf_shutdown ( &dns->socket, rc );
97
 	intf_shutdown ( &dns->resolv, rc );
95
 	intf_shutdown ( &dns->resolv, rc );
98
 }
96
 }
99
 
97
 
322
 /**
320
 /**
323
  * Receive new data
321
  * Receive new data
324
  *
322
  *
325
- * @v socket		UDP socket
326
- * @v data		DNS reply
327
- * @v len		Length of DNS reply
323
+ * @v dns		DNS request
324
+ * @v iobuf		I/O buffer
325
+ * @v meta		Data transfer metadata
328
  * @ret rc		Return status code
326
  * @ret rc		Return status code
329
  */
327
  */
330
-static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
331
-				  const void *data, size_t len ) {
332
-	struct dns_request *dns =
333
-		container_of ( socket, struct dns_request, socket );
334
-	const struct dns_header *reply = data;
328
+static int dns_xfer_deliver ( struct dns_request *dns,
329
+			      struct io_buffer *iobuf,
330
+			      struct xfer_metadata *meta __unused ) {
331
+	const struct dns_header *reply = iobuf->data;
335
 	union dns_rr_info *rr_info;
332
 	union dns_rr_info *rr_info;
336
 	struct sockaddr_in *sin;
333
 	struct sockaddr_in *sin;
337
 	unsigned int qtype = dns->qinfo->qtype;
334
 	unsigned int qtype = dns->qinfo->qtype;
335
+	int rc;
338
 
336
 
339
 	/* Sanity check */
337
 	/* Sanity check */
340
-	if ( len < sizeof ( *reply ) ) {
338
+	if ( iob_len ( iobuf ) < sizeof ( *reply ) ) {
341
 		DBGC ( dns, "DNS %p received underlength packet length %zd\n",
339
 		DBGC ( dns, "DNS %p received underlength packet length %zd\n",
342
-		       dns, len );
343
-		return -EINVAL;
340
+		       dns, iob_len ( iobuf ) );
341
+		rc = -EINVAL;
342
+		goto done;
344
 	}
343
 	}
345
 
344
 
346
 	/* Check reply ID matches query ID */
345
 	/* Check reply ID matches query ID */
348
 		DBGC ( dns, "DNS %p received unexpected reply ID %d "
347
 		DBGC ( dns, "DNS %p received unexpected reply ID %d "
349
 		       "(wanted %d)\n", dns, ntohs ( reply->id ),
348
 		       "(wanted %d)\n", dns, ntohs ( reply->id ),
350
 		       ntohs ( dns->query.dns.id ) );
349
 		       ntohs ( dns->query.dns.id ) );
351
-		return -EINVAL;
350
+		rc = -EINVAL;
351
+		goto done;
352
 	}
352
 	}
353
 
353
 
354
 	DBGC ( dns, "DNS %p received reply ID %d\n", dns, ntohs ( reply->id ));
354
 	DBGC ( dns, "DNS %p received reply ID %d\n", dns, ntohs ( reply->id ));
382
 
382
 
383
 			/* Mark operation as complete */
383
 			/* Mark operation as complete */
384
 			dns_done ( dns, 0 );
384
 			dns_done ( dns, 0 );
385
-			return 0;
385
+			rc = 0;
386
+			goto done;
386
 
387
 
387
 		case htons ( DNS_TYPE_CNAME ):
388
 		case htons ( DNS_TYPE_CNAME ):
388
 
389
 
399
 				DBGC ( dns, "DNS %p recursion exceeded\n",
400
 				DBGC ( dns, "DNS %p recursion exceeded\n",
400
 				       dns );
401
 				       dns );
401
 				dns_done ( dns, -ELOOP );
402
 				dns_done ( dns, -ELOOP );
402
-				return 0;
403
+				rc = 0;
404
+				goto done;
403
 			}
405
 			}
404
 			break;
406
 			break;
405
 
407
 
422
 		DBGC ( dns, "DNS %p found no A record; trying CNAME\n", dns );
424
 		DBGC ( dns, "DNS %p found no A record; trying CNAME\n", dns );
423
 		dns->qinfo->qtype = htons ( DNS_TYPE_CNAME );
425
 		dns->qinfo->qtype = htons ( DNS_TYPE_CNAME );
424
 		dns_send_packet ( dns );
426
 		dns_send_packet ( dns );
425
-		return 0;
427
+		rc = 0;
428
+		goto done;
426
 
429
 
427
 	case htons ( DNS_TYPE_CNAME ):
430
 	case htons ( DNS_TYPE_CNAME ):
428
 		/* We asked for a CNAME record.  If we got a response
431
 		/* We asked for a CNAME record.  If we got a response
431
 		 */
434
 		 */
432
 		if ( dns->qinfo->qtype == htons ( DNS_TYPE_A ) ) {
435
 		if ( dns->qinfo->qtype == htons ( DNS_TYPE_A ) ) {
433
 			dns_send_packet ( dns );
436
 			dns_send_packet ( dns );
434
-			return 0;
437
+			rc = 0;
438
+			goto done;
435
 		} else {
439
 		} else {
436
 			DBGC ( dns, "DNS %p found no CNAME record\n", dns );
440
 			DBGC ( dns, "DNS %p found no CNAME record\n", dns );
437
 			dns_done ( dns, -ENXIO );
441
 			dns_done ( dns, -ENXIO );
438
-			return 0;
442
+			rc = 0;
443
+			goto done;
439
 		}
444
 		}
440
 
445
 
441
 	default:
446
 	default:
442
 		assert ( 0 );
447
 		assert ( 0 );
443
 		dns_done ( dns, -EINVAL );
448
 		dns_done ( dns, -EINVAL );
444
-		return 0;
449
+		rc = -EINVAL;
450
+		goto done;
445
 	}
451
 	}
452
+
453
+ done:
454
+	/* Free I/O buffer */
455
+	free_iob ( iobuf );
456
+	return rc;
446
 }
457
 }
447
 
458
 
448
 /**
459
 /**
449
  * Receive new data
460
  * Receive new data
450
  *
461
  *
451
- * @v socket		UDP socket
462
+ * @v dns		DNS request
452
  * @v rc		Reason for close
463
  * @v rc		Reason for close
453
  */
464
  */
454
-static void dns_xfer_close ( struct xfer_interface *socket, int rc ) {
455
-	struct dns_request *dns =
456
-		container_of ( socket, struct dns_request, socket );
465
+static void dns_xfer_close ( struct dns_request *dns, int rc ) {
457
 
466
 
458
 	if ( ! rc )
467
 	if ( ! rc )
459
 		rc = -ECONNABORTED;
468
 		rc = -ECONNABORTED;
461
 	dns_done ( dns, rc );
470
 	dns_done ( dns, rc );
462
 }
471
 }
463
 
472
 
464
-/** DNS socket operations */
465
-static struct xfer_interface_operations dns_socket_operations = {
466
-	.close		= dns_xfer_close,
467
-	.vredirect	= xfer_vreopen,
468
-	.window		= unlimited_xfer_window,
469
-	.alloc_iob	= default_xfer_alloc_iob,
470
-	.deliver_iob	= xfer_deliver_as_raw,
471
-	.deliver_raw	= dns_xfer_deliver_raw,
473
+/** DNS socket interface operations */
474
+static struct interface_operation dns_socket_operations[] = {
475
+	INTF_OP ( xfer_deliver, struct dns_request *, dns_xfer_deliver ),
476
+	INTF_OP ( intf_close, struct dns_request *, dns_xfer_close ),
472
 };
477
 };
473
 
478
 
479
+/** DNS socket interface descriptor */
480
+static struct interface_descriptor dns_socket_desc =
481
+	INTF_DESC ( struct dns_request, socket, dns_socket_operations );
482
+
474
 /** DNS resolver interface operations */
483
 /** DNS resolver interface operations */
475
 static struct interface_operation dns_resolv_op[] = {
484
 static struct interface_operation dns_resolv_op[] = {
476
 	INTF_OP ( intf_close, struct dns_request *, dns_done ),
485
 	INTF_OP ( intf_close, struct dns_request *, dns_done ),
517
 	}
526
 	}
518
 	ref_init ( &dns->refcnt, NULL );
527
 	ref_init ( &dns->refcnt, NULL );
519
 	intf_init ( &dns->resolv, &dns_resolv_desc, &dns->refcnt );
528
 	intf_init ( &dns->resolv, &dns_resolv_desc, &dns->refcnt );
520
-	xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
529
+	intf_init ( &dns->socket, &dns_socket_desc, &dns->refcnt );
521
 	timer_init ( &dns->timer, dns_timer_expired );
530
 	timer_init ( &dns->timer, dns_timer_expired );
522
 	memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
531
 	memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
523
 
532
 

+ 38
- 96
src/net/udp/slam.c View File

119
 	struct refcnt refcnt;
119
 	struct refcnt refcnt;
120
 
120
 
121
 	/** Data transfer interface */
121
 	/** Data transfer interface */
122
-	struct xfer_interface xfer;
122
+	struct interface xfer;
123
 	/** Unicast socket */
123
 	/** Unicast socket */
124
-	struct xfer_interface socket;
124
+	struct interface socket;
125
 	/** Multicast socket */
125
 	/** Multicast socket */
126
-	struct xfer_interface mc_socket;
126
+	struct interface mc_socket;
127
 
127
 
128
 	/** Master client retry timer */
128
 	/** Master client retry timer */
129
 	struct retry_timer master_timer;
129
 	struct retry_timer master_timer;
184
 	stop_timer ( &slam->slave_timer );
184
 	stop_timer ( &slam->slave_timer );
185
 
185
 
186
 	/* Close all data transfer interfaces */
186
 	/* Close all data transfer interfaces */
187
-	xfer_nullify ( &slam->socket );
188
-	xfer_close ( &slam->socket, rc );
189
-	xfer_nullify ( &slam->mc_socket );
190
-	xfer_close ( &slam->mc_socket, rc );
191
-	xfer_nullify ( &slam->xfer );
192
-	xfer_close ( &slam->xfer, rc );
187
+	intf_shutdown ( &slam->socket, rc );
188
+	intf_shutdown ( &slam->mc_socket, rc );
189
+	intf_shutdown ( &slam->xfer, rc );
193
 }
190
 }
194
 
191
 
195
 /****************************************************************************
192
 /****************************************************************************
473
 /**
470
 /**
474
  * Receive SLAM data packet
471
  * Receive SLAM data packet
475
  *
472
  *
476
- * @v mc_socket		SLAM multicast socket
473
+ * @v slam		SLAM request
477
  * @v iobuf		I/O buffer
474
  * @v iobuf		I/O buffer
478
  * @ret rc		Return status code
475
  * @ret rc		Return status code
479
  */
476
  */
480
-static int slam_mc_socket_deliver ( struct xfer_interface *mc_socket,
477
+static int slam_mc_socket_deliver ( struct slam_request *slam,
481
 				    struct io_buffer *iobuf,
478
 				    struct io_buffer *iobuf,
482
 				    struct xfer_metadata *rx_meta __unused ) {
479
 				    struct xfer_metadata *rx_meta __unused ) {
483
-	struct slam_request *slam =
484
-		container_of ( mc_socket, struct slam_request, mc_socket );
485
 	struct xfer_metadata meta;
480
 	struct xfer_metadata meta;
486
 	unsigned long packet;
481
 	unsigned long packet;
487
 	size_t len;
482
 	size_t len;
533
 	memset ( &meta, 0, sizeof ( meta ) );
528
 	memset ( &meta, 0, sizeof ( meta ) );
534
 	meta.whence = SEEK_SET;
529
 	meta.whence = SEEK_SET;
535
 	meta.offset = ( packet * slam->block_size );
530
 	meta.offset = ( packet * slam->block_size );
536
-	if ( ( rc = xfer_deliver_iob_meta ( &slam->xfer, iobuf,
537
-					    &meta ) ) != 0 )
531
+	if ( ( rc = xfer_deliver ( &slam->xfer, iobuf, &meta ) ) != 0 )
538
 		goto err;
532
 		goto err;
539
 
533
 
540
 	/* Mark block as received */
534
 	/* Mark block as received */
556
 /**
550
 /**
557
  * Receive SLAM non-data packet
551
  * Receive SLAM non-data packet
558
  *
552
  *
559
- * @v socket		SLAM unicast socket
553
+ * @v slam		SLAM request
560
  * @v iobuf		I/O buffer
554
  * @v iobuf		I/O buffer
561
  * @ret rc		Return status code
555
  * @ret rc		Return status code
562
  */
556
  */
563
-static int slam_socket_deliver ( struct xfer_interface *socket,
557
+static int slam_socket_deliver ( struct slam_request *slam,
564
 				 struct io_buffer *iobuf,
558
 				 struct io_buffer *iobuf,
565
 				 struct xfer_metadata *rx_meta __unused ) {
559
 				 struct xfer_metadata *rx_meta __unused ) {
566
-	struct slam_request *slam =
567
-		container_of ( socket, struct slam_request, socket );
568
 	int rc;
560
 	int rc;
569
 
561
 
570
 	/* Restart the master client timer */
562
 	/* Restart the master client timer */
597
 
589
 
598
 }
590
 }
599
 
591
 
600
-/**
601
- * Close SLAM unicast socket
602
- *
603
- * @v socket		SLAM unicast socket
604
- * @v rc		Reason for close
605
- */
606
-static void slam_socket_close ( struct xfer_interface *socket, int rc ) {
607
-	struct slam_request *slam =
608
-		container_of ( socket, struct slam_request, socket );
609
-
610
-	DBGC ( slam, "SLAM %p unicast socket closed: %s\n",
611
-	       slam, strerror ( rc ) );
612
-
613
-	slam_finished ( slam, rc );
614
-}
615
-
616
-/** SLAM unicast socket data transfer operations */
617
-static struct xfer_interface_operations slam_socket_operations = {
618
-	.close		= slam_socket_close,
619
-	.vredirect	= xfer_vreopen,
620
-	.window		= unlimited_xfer_window,
621
-	.alloc_iob	= default_xfer_alloc_iob,
622
-	.deliver_iob	= slam_socket_deliver,
623
-	.deliver_raw	= xfer_deliver_as_iob,
592
+/** SLAM unicast socket interface operations */
593
+static struct interface_operation slam_socket_operations[] = {
594
+	INTF_OP ( xfer_deliver, struct slam_request *, slam_socket_deliver ),
595
+	INTF_OP ( intf_close, struct slam_request *, slam_finished ),
624
 };
596
 };
625
 
597
 
626
-/**
627
- * Close SLAM multicast socket
628
- *
629
- * @v mc_socket		SLAM multicast socket
630
- * @v rc		Reason for close
631
- */
632
-static void slam_mc_socket_close ( struct xfer_interface *mc_socket, int rc ){
633
-	struct slam_request *slam =
634
-		container_of ( mc_socket, struct slam_request, mc_socket );
635
-
636
-	DBGC ( slam, "SLAM %p multicast socket closed: %s\n",
637
-	       slam, strerror ( rc ) );
638
-
639
-	slam_finished ( slam, rc );
640
-}
598
+/** SLAM unicast socket interface descriptor */
599
+static struct interface_descriptor slam_socket_desc =
600
+	INTF_DESC ( struct slam_request, socket, slam_socket_operations );
641
 
601
 
642
-/** SLAM multicast socket data transfer operations */
643
-static struct xfer_interface_operations slam_mc_socket_operations = {
644
-	.close		= slam_mc_socket_close,
645
-	.vredirect	= xfer_vreopen,
646
-	.window		= unlimited_xfer_window,
647
-	.alloc_iob	= default_xfer_alloc_iob,
648
-	.deliver_iob	= slam_mc_socket_deliver,
649
-	.deliver_raw	= xfer_deliver_as_iob,
602
+/** SLAM multicast socket interface operations */
603
+static struct interface_operation slam_mc_socket_operations[] = {
604
+	INTF_OP ( xfer_deliver, struct slam_request *, slam_mc_socket_deliver ),
605
+	INTF_OP ( intf_close, struct slam_request *, slam_finished ),
650
 };
606
 };
651
 
607
 
608
+/** SLAM multicast socket interface descriptor */
609
+static struct interface_descriptor slam_mc_socket_desc =
610
+	INTF_DESC ( struct slam_request, mc_socket, slam_mc_socket_operations );
611
+
652
 /****************************************************************************
612
 /****************************************************************************
653
  *
613
  *
654
  * Data transfer interface
614
  * Data transfer interface
655
  *
615
  *
656
  */
616
  */
657
 
617
 
658
-/**
659
- * Close SLAM data transfer interface
660
- *
661
- * @v xfer		SLAM data transfer interface
662
- * @v rc		Reason for close
663
- */
664
-static void slam_xfer_close ( struct xfer_interface *xfer, int rc ) {
665
-	struct slam_request *slam =
666
-		container_of ( xfer, struct slam_request, xfer );
667
-
668
-	DBGC ( slam, "SLAM %p data transfer interface closed: %s\n",
669
-	       slam, strerror ( rc ) );
670
-
671
-	slam_finished ( slam, rc );
672
-}
673
-
674
-/** SLAM data transfer operations */
675
-static struct xfer_interface_operations slam_xfer_operations = {
676
-	.close		= slam_xfer_close,
677
-	.vredirect	= ignore_xfer_vredirect,
678
-	.window		= unlimited_xfer_window,
679
-	.alloc_iob	= default_xfer_alloc_iob,
680
-	.deliver_iob	= xfer_deliver_as_raw,
681
-	.deliver_raw	= ignore_xfer_deliver_raw,
618
+/** SLAM data transfer interface operations */
619
+static struct interface_operation slam_xfer_operations[] = {
620
+	INTF_OP ( intf_close, struct slam_request *, slam_finished ),
682
 };
621
 };
683
 
622
 
623
+/** SLAM data transfer interface descriptor */
624
+static struct interface_descriptor slam_xfer_desc =
625
+	INTF_DESC ( struct slam_request, xfer, slam_xfer_operations );
626
+
684
 /**
627
 /**
685
  * Parse SLAM URI multicast address
628
  * Parse SLAM URI multicast address
686
  *
629
  *
729
  * @v uri		Uniform Resource Identifier
672
  * @v uri		Uniform Resource Identifier
730
  * @ret rc		Return status code
673
  * @ret rc		Return status code
731
  */
674
  */
732
-static int slam_open ( struct xfer_interface *xfer, struct uri *uri ) {
675
+static int slam_open ( struct interface *xfer, struct uri *uri ) {
733
 	static const struct sockaddr_in default_multicast = {
676
 	static const struct sockaddr_in default_multicast = {
734
 		.sin_family = AF_INET,
677
 		.sin_family = AF_INET,
735
 		.sin_port = htons ( SLAM_DEFAULT_MULTICAST_PORT ),
678
 		.sin_port = htons ( SLAM_DEFAULT_MULTICAST_PORT ),
749
 	if ( ! slam )
692
 	if ( ! slam )
750
 		return -ENOMEM;
693
 		return -ENOMEM;
751
 	ref_init ( &slam->refcnt, slam_free );
694
 	ref_init ( &slam->refcnt, slam_free );
752
-	xfer_init ( &slam->xfer, &slam_xfer_operations, &slam->refcnt );
753
-	xfer_init ( &slam->socket, &slam_socket_operations, &slam->refcnt );
754
-	xfer_init ( &slam->mc_socket, &slam_mc_socket_operations,
755
-		    &slam->refcnt );
695
+	intf_init ( &slam->xfer, &slam_xfer_desc, &slam->refcnt );
696
+	intf_init ( &slam->socket, &slam_socket_desc, &slam->refcnt );
697
+	intf_init ( &slam->mc_socket, &slam_mc_socket_desc, &slam->refcnt );
756
 	timer_init ( &slam->master_timer, slam_master_timer_expired );
698
 	timer_init ( &slam->master_timer, slam_master_timer_expired );
757
 	timer_init ( &slam->slave_timer, slam_slave_timer_expired );
699
 	timer_init ( &slam->slave_timer, slam_slave_timer_expired );
758
 	/* Fake an invalid cached header of { 0x00, ... } */
700
 	/* Fake an invalid cached header of { 0x00, ... } */
795
 	start_timer_fixed ( &slam->slave_timer, SLAM_SLAVE_TIMEOUT );
737
 	start_timer_fixed ( &slam->slave_timer, SLAM_SLAVE_TIMEOUT );
796
 
738
 
797
 	/* Attach to parent interface, mortalise self, and return */
739
 	/* Attach to parent interface, mortalise self, and return */
798
-	xfer_plug_plug ( &slam->xfer, xfer );
740
+	intf_plug_plug ( &slam->xfer, xfer );
799
 	ref_put ( &slam->refcnt );
741
 	ref_put ( &slam->refcnt );
800
 	return 0;
742
 	return 0;
801
 
743
 

+ 46
- 88
src/net/udp/tftp.c View File

27
 #include <errno.h>
27
 #include <errno.h>
28
 #include <assert.h>
28
 #include <assert.h>
29
 #include <ipxe/refcnt.h>
29
 #include <ipxe/refcnt.h>
30
+#include <ipxe/iobuf.h>
30
 #include <ipxe/xfer.h>
31
 #include <ipxe/xfer.h>
31
 #include <ipxe/open.h>
32
 #include <ipxe/open.h>
32
 #include <ipxe/uri.h>
33
 #include <ipxe/uri.h>
79
 	/** Reference count */
80
 	/** Reference count */
80
 	struct refcnt refcnt;
81
 	struct refcnt refcnt;
81
 	/** Data transfer interface */
82
 	/** Data transfer interface */
82
-	struct xfer_interface xfer;
83
+	struct interface xfer;
83
 
84
 
84
 	/** URI being fetched */
85
 	/** URI being fetched */
85
 	struct uri *uri;
86
 	struct uri *uri;
86
 	/** Transport layer interface */
87
 	/** Transport layer interface */
87
-	struct xfer_interface socket;
88
+	struct interface socket;
88
 	/** Multicast transport layer interface */
89
 	/** Multicast transport layer interface */
89
-	struct xfer_interface mc_socket;
90
+	struct interface mc_socket;
90
 
91
 
91
 	/** Data block size
92
 	/** Data block size
92
 	 *
93
 	 *
183
 	stop_timer ( &tftp->timer );
184
 	stop_timer ( &tftp->timer );
184
 
185
 
185
 	/* Close all data transfer interfaces */
186
 	/* Close all data transfer interfaces */
186
-	xfer_nullify ( &tftp->socket );
187
-	xfer_close ( &tftp->socket, rc );
188
-	xfer_nullify ( &tftp->mc_socket );
189
-	xfer_close ( &tftp->mc_socket, rc );
190
-	xfer_nullify ( &tftp->xfer );
191
-	xfer_close ( &tftp->xfer, rc );
187
+	intf_shutdown ( &tftp->socket, rc );
188
+	intf_shutdown ( &tftp->mc_socket, rc );
189
+	intf_shutdown ( &tftp->xfer, rc );
192
 }
190
 }
193
 
191
 
194
 /**
192
 /**
202
 	int rc;
200
 	int rc;
203
 
201
 
204
 	/* Close socket */
202
 	/* Close socket */
205
-	xfer_close ( &tftp->socket, 0 );
203
+	intf_restart ( &tftp->socket, 0 );
206
 
204
 
207
 	/* Disable ACK sending. */
205
 	/* Disable ACK sending. */
208
 	tftp->flags &= ~TFTP_FL_SEND_ACK;
206
 	tftp->flags &= ~TFTP_FL_SEND_ACK;
236
 	int rc;
234
 	int rc;
237
 
235
 
238
 	/* Close multicast socket */
236
 	/* Close multicast socket */
239
-	xfer_close ( &tftp->mc_socket, 0 );
237
+	intf_restart ( &tftp->mc_socket, 0 );
240
 
238
 
241
 	/* Open multicast socket.  We never send via this socket, so
239
 	/* Open multicast socket.  We never send via this socket, so
242
 	 * use the local address as the peer address (since the peer
240
 	 * use the local address as the peer address (since the peer
423
 	ack->block = htons ( block );
421
 	ack->block = htons ( block );
424
 
422
 
425
 	/* ACK always goes to the peer recorded from the RRQ response */
423
 	/* ACK always goes to the peer recorded from the RRQ response */
426
-	return xfer_deliver_iob_meta ( &tftp->socket, iobuf, &meta );
424
+	return xfer_deliver ( &tftp->socket, iobuf, &meta );
427
 }
425
 }
428
 
426
 
429
 /**
427
 /**
459
 	strcpy ( err->errmsg, errmsg );
457
 	strcpy ( err->errmsg, errmsg );
460
 
458
 
461
 	/* ERR always goes to the peer recorded from the RRQ response */
459
 	/* ERR always goes to the peer recorded from the RRQ response */
462
-	return xfer_deliver_iob_meta ( &tftp->socket, iobuf, &meta );
460
+	return xfer_deliver ( &tftp->socket, iobuf, &meta );
463
 }
461
 }
464
 
462
 
465
 /**
463
 /**
525
 				tftp->flags = TFTP_FL_RRQ_SIZES;
523
 				tftp->flags = TFTP_FL_RRQ_SIZES;
526
 
524
 
527
 				/* Close multicast socket */
525
 				/* Close multicast socket */
528
-				xfer_close ( &tftp->mc_socket, 0 );
526
+				intf_restart ( &tftp->mc_socket, 0 );
529
 
527
 
530
 				/* Reset retry timer */
528
 				/* Reset retry timer */
531
 				start_timer_nodelay ( &tftp->timer );
529
 				start_timer_nodelay ( &tftp->timer );
858
 	memset ( &meta, 0, sizeof ( meta ) );
856
 	memset ( &meta, 0, sizeof ( meta ) );
859
 	meta.whence = SEEK_SET;
857
 	meta.whence = SEEK_SET;
860
 	meta.offset = offset;
858
 	meta.offset = offset;
861
-	if ( ( rc = xfer_deliver_iob_meta ( &tftp->xfer, iob_disown ( iobuf ),
862
-					    &meta ) ) != 0 ) {
859
+	if ( ( rc = xfer_deliver ( &tftp->xfer, iob_disown ( iobuf ),
860
+				   &meta ) ) != 0 ) {
863
 		DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
861
 		DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
864
 		       tftp, strerror ( rc ) );
862
 		       tftp, strerror ( rc ) );
865
 		goto done;
863
 		goto done;
998
 /**
996
 /**
999
  * Receive new data via socket
997
  * Receive new data via socket
1000
  *
998
  *
1001
- * @v socket		Transport layer interface
999
+ * @v tftp		TFTP connection
1002
  * @v iobuf		I/O buffer
1000
  * @v iobuf		I/O buffer
1003
  * @v meta		Transfer metadata
1001
  * @v meta		Transfer metadata
1004
  * @ret rc		Return status code
1002
  * @ret rc		Return status code
1005
  */
1003
  */
1006
-static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
1007
-				     struct io_buffer *iobuf,
1008
-				     struct xfer_metadata *meta ) {
1009
-	struct tftp_request *tftp =
1010
-		container_of ( socket, struct tftp_request, socket );
1004
+static int tftp_socket_deliver ( struct tftp_request *tftp,
1005
+				 struct io_buffer *iobuf,
1006
+				 struct xfer_metadata *meta ) {
1011
 
1007
 
1012
 	/* Enable sending ACKs when we receive a unicast packet.  This
1008
 	/* Enable sending ACKs when we receive a unicast packet.  This
1013
 	 * covers three cases:
1009
 	 * covers three cases:
1030
 }
1026
 }
1031
 
1027
 
1032
 /** TFTP socket operations */
1028
 /** TFTP socket operations */
1033
-static struct xfer_interface_operations tftp_socket_operations = {
1034
-	.close		= ignore_xfer_close,
1035
-	.vredirect	= xfer_vreopen,
1036
-	.window		= unlimited_xfer_window,
1037
-	.alloc_iob	= default_xfer_alloc_iob,
1038
-	.deliver_iob	= tftp_socket_deliver_iob,
1039
-	.deliver_raw	= xfer_deliver_as_iob,
1029
+static struct interface_operation tftp_socket_operations[] = {
1030
+	INTF_OP ( xfer_deliver, struct tftp_request *, tftp_socket_deliver ),
1040
 };
1031
 };
1041
 
1032
 
1042
-/**
1043
- * Receive new data via multicast socket
1044
- *
1045
- * @v mc_socket		Multicast transport layer interface
1046
- * @v iobuf		I/O buffer
1047
- * @v meta		Transfer metadata
1048
- * @ret rc		Return status code
1049
- */
1050
-static int tftp_mc_socket_deliver_iob ( struct xfer_interface *mc_socket,
1051
-					struct io_buffer *iobuf,
1052
-					struct xfer_metadata *meta ) {
1053
-	struct tftp_request *tftp =
1054
-		container_of ( mc_socket, struct tftp_request, mc_socket );
1055
-
1056
-	return tftp_rx ( tftp, iobuf, meta );
1057
-}
1033
+/** TFTP socket interface descriptor */
1034
+static struct interface_descriptor tftp_socket_desc =
1035
+	INTF_DESC ( struct tftp_request, socket, tftp_socket_operations );
1058
 
1036
 
1059
 /** TFTP multicast socket operations */
1037
 /** TFTP multicast socket operations */
1060
-static struct xfer_interface_operations tftp_mc_socket_operations = {
1061
-	.close		= ignore_xfer_close,
1062
-	.vredirect	= xfer_vreopen,
1063
-	.window		= unlimited_xfer_window,
1064
-	.alloc_iob	= default_xfer_alloc_iob,
1065
-	.deliver_iob	= tftp_mc_socket_deliver_iob,
1066
-	.deliver_raw	= xfer_deliver_as_iob,
1038
+static struct interface_operation tftp_mc_socket_operations[] = {
1039
+	INTF_OP ( xfer_deliver, struct tftp_request *, tftp_rx ),
1067
 };
1040
 };
1068
 
1041
 
1069
-/**
1070
- * Close TFTP data transfer interface
1071
- *
1072
- * @v xfer		Data transfer interface
1073
- * @v rc		Reason for close
1074
- */
1075
-static void tftp_xfer_close ( struct xfer_interface *xfer, int rc ) {
1076
-	struct tftp_request *tftp =
1077
-		container_of ( xfer, struct tftp_request, xfer );
1078
-
1079
-	DBGC ( tftp, "TFTP %p interface closed: %s\n",
1080
-	       tftp, strerror ( rc ) );
1081
-
1082
-	tftp_done ( tftp, rc );
1083
-}
1042
+/** TFTP multicast socket interface descriptor */
1043
+static struct interface_descriptor tftp_mc_socket_desc =
1044
+	INTF_DESC ( struct tftp_request, mc_socket, tftp_mc_socket_operations );
1084
 
1045
 
1085
 /**
1046
 /**
1086
  * Check flow control window
1047
  * Check flow control window
1087
  *
1048
  *
1088
- * @v xfer		Data transfer interface
1049
+ * @v tftp		TFTP connection
1089
  * @ret len		Length of window
1050
  * @ret len		Length of window
1090
  */
1051
  */
1091
-static size_t tftp_xfer_window ( struct xfer_interface *xfer ) {
1092
-	struct tftp_request *tftp =
1093
-		container_of ( xfer, struct tftp_request, xfer );
1052
+static size_t tftp_xfer_window ( struct tftp_request *tftp ) {
1094
 
1053
 
1095
 	/* We abuse this data-xfer method to convey the blocksize to
1054
 	/* We abuse this data-xfer method to convey the blocksize to
1096
 	 * the caller.  This really should be done using some kind of
1055
 	 * the caller.  This really should be done using some kind of
1101
 }
1060
 }
1102
 
1061
 
1103
 /** TFTP data transfer interface operations */
1062
 /** TFTP data transfer interface operations */
1104
-static struct xfer_interface_operations tftp_xfer_operations = {
1105
-	.close		= tftp_xfer_close,
1106
-	.vredirect	= ignore_xfer_vredirect,
1107
-	.window		= tftp_xfer_window,
1108
-	.alloc_iob	= default_xfer_alloc_iob,
1109
-	.deliver_iob	= xfer_deliver_as_raw,
1110
-	.deliver_raw	= ignore_xfer_deliver_raw,
1063
+static struct interface_operation tftp_xfer_operations[] = {
1064
+	INTF_OP ( xfer_window, struct tftp_request *, tftp_xfer_window ),
1065
+	INTF_OP ( intf_close, struct tftp_request *, tftp_done ),
1111
 };
1066
 };
1112
 
1067
 
1068
+/** TFTP data transfer interface descriptor */
1069
+static struct interface_descriptor tftp_xfer_desc =
1070
+	INTF_DESC ( struct tftp_request, xfer, tftp_xfer_operations );
1071
+
1113
 /**
1072
 /**
1114
  * Initiate TFTP/TFTM/MTFTP download
1073
  * Initiate TFTP/TFTM/MTFTP download
1115
  *
1074
  *
1117
  * @v uri		Uniform Resource Identifier
1076
  * @v uri		Uniform Resource Identifier
1118
  * @ret rc		Return status code
1077
  * @ret rc		Return status code
1119
  */
1078
  */
1120
-static int tftp_core_open ( struct xfer_interface *xfer, struct uri *uri,
1079
+static int tftp_core_open ( struct interface *xfer, struct uri *uri,
1121
 			    unsigned int default_port,
1080
 			    unsigned int default_port,
1122
 			    struct sockaddr *multicast,
1081
 			    struct sockaddr *multicast,
1123
 			    unsigned int flags ) {
1082
 			    unsigned int flags ) {
1135
 	if ( ! tftp )
1094
 	if ( ! tftp )
1136
 		return -ENOMEM;
1095
 		return -ENOMEM;
1137
 	ref_init ( &tftp->refcnt, tftp_free );
1096
 	ref_init ( &tftp->refcnt, tftp_free );
1138
-	xfer_init ( &tftp->xfer, &tftp_xfer_operations, &tftp->refcnt );
1139
-	xfer_init ( &tftp->socket, &tftp_socket_operations, &tftp->refcnt );
1140
-	xfer_init ( &tftp->mc_socket, &tftp_mc_socket_operations,
1141
-		    &tftp->refcnt );
1097
+	intf_init ( &tftp->xfer, &tftp_xfer_desc, &tftp->refcnt );
1098
+	intf_init ( &tftp->socket, &tftp_socket_desc, &tftp->refcnt );
1099
+	intf_init ( &tftp->mc_socket, &tftp_mc_socket_desc, &tftp->refcnt );
1142
 	timer_init ( &tftp->timer, tftp_timer_expired );
1100
 	timer_init ( &tftp->timer, tftp_timer_expired );
1143
 	tftp->uri = uri_get ( uri );
1101
 	tftp->uri = uri_get ( uri );
1144
 	tftp->blksize = TFTP_DEFAULT_BLKSIZE;
1102
 	tftp->blksize = TFTP_DEFAULT_BLKSIZE;
1159
 	start_timer_nodelay ( &tftp->timer );
1117
 	start_timer_nodelay ( &tftp->timer );
1160
 
1118
 
1161
 	/* Attach to parent interface, mortalise self, and return */
1119
 	/* Attach to parent interface, mortalise self, and return */
1162
-	xfer_plug_plug ( &tftp->xfer, xfer );
1120
+	intf_plug_plug ( &tftp->xfer, xfer );
1163
 	ref_put ( &tftp->refcnt );
1121
 	ref_put ( &tftp->refcnt );
1164
 	return 0;
1122
 	return 0;
1165
 
1123
 
1178
  * @v uri		Uniform Resource Identifier
1136
  * @v uri		Uniform Resource Identifier
1179
  * @ret rc		Return status code
1137
  * @ret rc		Return status code
1180
  */
1138
  */
1181
-static int tftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
1139
+static int tftp_open ( struct interface *xfer, struct uri *uri ) {
1182
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1140
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1183
 				TFTP_FL_RRQ_SIZES );
1141
 				TFTP_FL_RRQ_SIZES );
1184
 
1142
 
1197
  * @v uri		Uniform Resource Identifier
1155
  * @v uri		Uniform Resource Identifier
1198
  * @ret rc		Return status code
1156
  * @ret rc		Return status code
1199
  */
1157
  */
1200
-static int tftpsize_open ( struct xfer_interface *xfer, struct uri *uri ) {
1158
+static int tftpsize_open ( struct interface *xfer, struct uri *uri ) {
1201
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1159
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1202
 				( TFTP_FL_RRQ_SIZES |
1160
 				( TFTP_FL_RRQ_SIZES |
1203
 				  TFTP_FL_SIZEONLY ) );
1161
 				  TFTP_FL_SIZEONLY ) );
1217
  * @v uri		Uniform Resource Identifier
1175
  * @v uri		Uniform Resource Identifier
1218
  * @ret rc		Return status code
1176
  * @ret rc		Return status code
1219
  */
1177
  */
1220
-static int tftm_open ( struct xfer_interface *xfer, struct uri *uri ) {
1178
+static int tftm_open ( struct interface *xfer, struct uri *uri ) {
1221
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1179
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1222
 				( TFTP_FL_RRQ_SIZES |
1180
 				( TFTP_FL_RRQ_SIZES |
1223
 				  TFTP_FL_RRQ_MULTICAST ) );
1181
 				  TFTP_FL_RRQ_MULTICAST ) );
1237
  * @v uri		Uniform Resource Identifier
1195
  * @v uri		Uniform Resource Identifier
1238
  * @ret rc		Return status code
1196
  * @ret rc		Return status code
1239
  */
1197
  */
1240
-static int mtftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
1198
+static int mtftp_open ( struct interface *xfer, struct uri *uri ) {
1241
 	return tftp_core_open ( xfer, uri, MTFTP_PORT,
1199
 	return tftp_core_open ( xfer, uri, MTFTP_PORT,
1242
 				( struct sockaddr * ) &tftp_mtftp_socket,
1200
 				( struct sockaddr * ) &tftp_mtftp_socket,
1243
 				TFTP_FL_MTFTP_RECOVERY );
1201
 				TFTP_FL_MTFTP_RECOVERY );

Loading…
Cancel
Save